First test of network, string as input
This commit is contained in:
parent
fe1f907759
commit
a50474ef9b
13 changed files with 111 additions and 167 deletions
|
|
@ -1,12 +1,2 @@
|
||||||
[
|
[
|
||||||
{"name":"Temperature converter","description":r"""
|
|
||||||
Simple temperature converter example that returns the input value (Kelvin) as output.
|
|
||||||
|
|
||||||
Formula: $$T_{out} = T_{in}$$
|
|
||||||
|
|
||||||
Inputs: `Input` in kelvin (K).
|
|
||||||
Output: `Output` in kelvin (K).
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"Input","unit":"Kelvin"}],"output":{"name":"Output","unit":"Kelvin"},"d4rtCode":"Output = Input;","tags":["converter","temperature"]}
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,2 @@
|
||||||
[
|
[
|
||||||
{"name":"Kinetic Energy","description":r"""
|
|
||||||
Energy possessed by a moving object.
|
|
||||||
|
|
||||||
$$KE = \frac{1}{2}mv^2$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $m$: Mass (kg)
|
|
||||||
- $v$: Velocity (m/s)
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"m","unit":"kilogram"},{"name":"v","unit":"meters per second"}],"output":{"name":"KE","unit":"joule"},"d4rtCode":"KE = 0.5 * m * pow(v, 2);","tags":["physics","energy","mechanics"]},
|
|
||||||
{"name":"Work","description":r"""
|
|
||||||
Energy transferred when a force moves an object.
|
|
||||||
|
|
||||||
$$W = F d \cos(\theta)$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $W$: Work (Joules)
|
|
||||||
- $F$: Force (Newtons)
|
|
||||||
- $d$: Displacement (meters)
|
|
||||||
- $\theta$: Angle between force and displacement
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"F","unit":"newton"},{"name":"d","unit":"meter"},{"name":"theta","unit":"degree"}],"output":{"name":"W","unit":"joule"},"d4rtCode":"var thetaRad = theta * (pi / 180); W = F * d * cos(thetaRad);","tags":["physics","energy","mechanics"]},
|
|
||||||
{"name":"Power","description":r"""
|
|
||||||
Rate at which work is done or energy is transferred.
|
|
||||||
|
|
||||||
$$P = \frac{W}{t}$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $P$: Power (Watts)
|
|
||||||
- $W$: Work or energy (Joules)
|
|
||||||
- $t$: Time (seconds)
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"W","unit":"joule"},{"name":"t","unit":"second"}],"output":{"name":"P","unit":"watt"},"d4rtCode":"P = W / t;","tags":["physics","energy","mechanics"]},
|
|
||||||
{"name":"Mass-Energy Equivalence","description":r"""
|
|
||||||
Einstein's mass-energy equivalence relation.
|
|
||||||
|
|
||||||
$$E = mc^2$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $E$: Energy (Joules)
|
|
||||||
- $m$: Mass (kg)
|
|
||||||
- $c$: Speed of light $299{,}792{,}458\ \mathrm{m/s}$
|
|
||||||
|
|
||||||
This shows mass can be converted to energy and vice versa.
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"m","unit":"kilogram"}],"output":{"name":"E","unit":"joule"},"d4rtCode":"E = m * pow(299792458, 2);","tags":["physics","relativity","energy"]}
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -10,51 +10,6 @@
|
||||||
"d4rtCode": "Output = Input;",
|
"d4rtCode": "Output = Input;",
|
||||||
"tags": ["converter", "temperature" ]
|
"tags": ["converter", "temperature" ]
|
||||||
},
|
},
|
||||||
// Free fall distance (vertical)
|
|
||||||
{
|
|
||||||
"name": "Free Fall Distance",
|
|
||||||
"description": r"""
|
|
||||||
Calculates vertical displacement under constant gravity
|
|
||||||
|
|
||||||
$$h = \frac{1}{2}gt^2$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $g$: Gravitational acceleration $9.81\ \mathrm{m/s^2}$ on Earth
|
|
||||||
- $t$: Time in free fall (seconds)
|
|
||||||
|
|
||||||
""",
|
|
||||||
"input": [
|
|
||||||
{"name": "t", "unit": "second"}, // Time in seconds
|
|
||||||
{"name": "g", "unit": "meters per second"} // Gravitational acceleration
|
|
||||||
],
|
|
||||||
"output": {"name": "h", "unit": "meter"}, // Height in meters
|
|
||||||
"d4rtCode": "h = 0.5 * g * pow(t, 2);",
|
|
||||||
"tags": ["physics", "kinematics"]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Newton's Law of Universal Gravitation
|
|
||||||
{
|
|
||||||
"name": "Gravitational Force",
|
|
||||||
"description": r'''
|
|
||||||
Newton's law of universal gravitation
|
|
||||||
|
|
||||||
\(F = G\frac{m_1m_2}{r^2}\)
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $G$: Gravitational constant $6.674\times 10^{-11}\ \mathrm{N\cdot m^2/kg^2}$
|
|
||||||
- $m_1, m_2$: Masses of two objects
|
|
||||||
- $r$: Distance between centers of masses
|
|
||||||
|
|
||||||
''',
|
|
||||||
"input": [
|
|
||||||
{"name": "m1", "unit": "kilogram"}, // Mass 1
|
|
||||||
{"name": "m2", "unit": "kilogram"}, // Mass 2
|
|
||||||
{"name": "r", "unit": "meter"} // Distance between masses
|
|
||||||
],
|
|
||||||
"output": {"name": "F", "unit": "newton"}, // Force in newtons
|
|
||||||
"d4rtCode": "F = (6.67430e-11 * m1 * m2) / pow(r, 2);",
|
|
||||||
"tags": ["physics", "astronomy", "gravity"]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Kinetic Energy
|
// Kinetic Energy
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
[
|
||||||
|
// Free fall distance (vertical)
|
||||||
|
{
|
||||||
|
"name": "Free Fall Distance",
|
||||||
|
"description": r"""
|
||||||
|
Calculates vertical displacement under constant gravity
|
||||||
|
|
||||||
|
$$h = \frac{1}{2}gt^2$$
|
||||||
|
|
||||||
|
Where:
|
||||||
|
- $g$: Gravitational acceleration $9.81\ \mathrm{m/s^2}$ on Earth
|
||||||
|
- $t$: Time in free fall (seconds)
|
||||||
|
|
||||||
|
""",
|
||||||
|
"input": [
|
||||||
|
{"name": "t", "unit": "second"}, // Time in seconds
|
||||||
|
{"name": "g", "unit": "meters per second"} // Gravitational acceleration
|
||||||
|
],
|
||||||
|
"output": {"name": "h", "unit": "meter"}, // Height in meters
|
||||||
|
"d4rtCode": "h = 0.5 * g * pow(t, 2);",
|
||||||
|
"tags": ["physics", "kinematics"]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Newton's Law of Universal Gravitation
|
||||||
|
{
|
||||||
|
"name": "Gravitational Force",
|
||||||
|
"description": r'''
|
||||||
|
Newton's law of universal gravitation
|
||||||
|
|
||||||
|
\(F = G\frac{m_1m_2}{r^2}\)
|
||||||
|
|
||||||
|
Where:
|
||||||
|
- $G$: Gravitational constant $6.674\times 10^{-11}\ \mathrm{N\cdot m^2/kg^2}$
|
||||||
|
- $m_1, m_2$: Masses of two objects
|
||||||
|
- $r$: Distance between centers of masses
|
||||||
|
|
||||||
|
''',
|
||||||
|
"input": [
|
||||||
|
{"name": "m1", "unit": "kilogram"}, // Mass 1
|
||||||
|
{"name": "m2", "unit": "kilogram"}, // Mass 2
|
||||||
|
{"name": "r", "unit": "meter"} // Distance between masses
|
||||||
|
],
|
||||||
|
"output": {"name": "F", "unit": "newton"}, // Force in newtons
|
||||||
|
"d4rtCode": "F = (6.67430e-11 * m1 * m2) / pow(r, 2);",
|
||||||
|
"tags": ["physics", "astronomy", "gravity"]
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
37
assets/formulas/it-networking.d4rt
Normal file
37
assets/formulas/it-networking.d4rt
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Network Address from Host IP",
|
||||||
|
"description": r"""Calculates the network address from a host IP/MASK notation.
|
||||||
|
|
||||||
|
Given a host IP address and subnet mask in CIDR notation (e.g., 192.168.1.100/24),
|
||||||
|
this formula extracts the network address (e.g., 192.168.1.0/24).
|
||||||
|
|
||||||
|
Where:
|
||||||
|
- Host IP/MASK: IP address with CIDR subnet mask (e.g., 192.168.1.100/24)
|
||||||
|
- Network: The resulting network address in IP/MASK format (e.g., 192.168.1.0/24)
|
||||||
|
|
||||||
|
The network address is calculated by applying the subnet mask to zero out the host bits.""",
|
||||||
|
"input": [
|
||||||
|
{"name": "hostIP", "unit": "string"}
|
||||||
|
],
|
||||||
|
"output": {"name": "network", "unit": "string"},
|
||||||
|
"d4rtCode": r"""var parts = hostIP.split('/');
|
||||||
|
var ip = parts[0];
|
||||||
|
var mask = int.parse(parts[1]);
|
||||||
|
var octets = ip.split('.').map((e) => int.parse(e)).toList();
|
||||||
|
var hostBits = 32 - mask;
|
||||||
|
var shiftAmount = hostBits;
|
||||||
|
var networkValue = 0;
|
||||||
|
for (var i = 0; i < 4; i++) {
|
||||||
|
networkValue = (networkValue << 8) | octets[i];
|
||||||
|
}
|
||||||
|
networkValue = (networkValue >> shiftAmount) << shiftAmount;
|
||||||
|
var networkOctets = [];
|
||||||
|
for (var i = 0; i < 4; i++) {
|
||||||
|
networkOctets.insert(0, networkValue & 0xFF);
|
||||||
|
networkValue = networkValue >> 8;
|
||||||
|
}
|
||||||
|
network = networkOctets.join('.') + '/' + mask.toString();""",
|
||||||
|
"tags": ["networking", "ip", "subnetting", "cidr", "network"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
[
|
||||||
|
]
|
||||||
|
|
@ -1,16 +1,4 @@
|
||||||
[
|
[
|
||||||
{"name":"Hooke's Law","description":r"""
|
{"name":"Hooke's Law","input":[{"name":"k","unit":"newton per meter"},{"name":"x","unit":"meter"}],"output":{"name":"F","unit":"newton"},"d4rtCode":"F = -k * x;","tags":["physics","elasticity","oscillations"]}
|
||||||
Force exerted by a spring is proportional to its displacement (linear region).
|
|
||||||
|
|
||||||
$$F = -kx$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $F$: Restoring force (Newtons)
|
|
||||||
- $k$: Spring constant (N/m)
|
|
||||||
- $x$: Displacement from equilibrium (meters)
|
|
||||||
|
|
||||||
The negative sign indicates the force opposes displacement.
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"k","unit":"newton per meter"},{"name":"x","unit":"meter"}],"output":{"name":"F","unit":"newton"},"d4rtCode":"F = -k * x;","tags":["physics","elasticity","oscillations"]}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,4 @@
|
||||||
[
|
[
|
||||||
{"name":"Apgar Score","description":r"""
|
{"name":"Apgar Score","input":[{"name":"HeartRate","values":["Absent","< 100 bpm>","> 100 bpm"]},{"name":"Breathing","values":["Absent","Weak, irregular","Strong, robust cry"]},{"name":"MuscleTone","values":["None","Some","Flexed arms/leg, resists extension"]},{"name":"Reflexes","values":["No response","Grimace on aggressive stimulation","Cry on stimulation"]},{"name":"SkinColor","values":["Blue or pale","Blue extremities, pink body","Pink"]}],"output":{"name":"Result","unit":"string"},"d4rtCode":"var total = indexOf(\"HeartRate\") + indexOf(\"Breathing\") + indexOf(\"MuscleTone\") + indexOf(\"Reflexes\") + indexOf(\"SkinColor\"); late var interpretation; if( total < 4 ) { interpretation = 'Critical condition'; } else if( total < 7 ){ interpretation = 'Needs assistance'; } else { interpretation = 'Normal'; } Result = 'Score: \$total - \$interpretation';","tags":["medical","pediatrics","assessment"]}
|
||||||
Newborn health assessment scoring system performed at 1 and 5 minutes after birth.
|
|
||||||
|
|
||||||
The Apgar score sums five categories (0–2 points each):
|
|
||||||
1. Heart rate
|
|
||||||
2. Respiratory effort
|
|
||||||
3. Muscle tone
|
|
||||||
4. Reflex response
|
|
||||||
5. Color
|
|
||||||
|
|
||||||
Total score ranges from 0 to 10. Higher scores indicate better newborn condition.
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"HeartRate","values":["Absent","< 100 bpm>","> 100 bpm"]},{"name":"Breathing","values":["Absent","Weak, irregular","Strong, robust cry"]},{"name":"MuscleTone","values":["None","Some","Flexed arms/leg, resists extension"]},{"name":"Reflexes","values":["No response","Grimace on aggressive stimulation","Cry on stimulation"]},{"name":"SkinColor","values":["Blue or pale","Blue extremities, pink body","Pink"]}],"output":{"name":"Result","unit":"string"},"d4rtCode":"var total = indexOf(\"HeartRate\") + indexOf(\"Breathing\") + indexOf(\"MuscleTone\") + indexOf(\"Reflexes\") + indexOf(\"SkinColor\"); late var interpretation; if( total < 4 ) { interpretation = 'Critical condition'; } else if( total < 7 ){ interpretation = 'Needs assistance'; } else { interpretation = 'Normal'; } Result = 'Score: \$total - \$interpretation';","tags":["medical","pediatrics","assessment"]}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,4 @@
|
||||||
[
|
[
|
||||||
{"name":"Snell's Law","description":r"""
|
{"name":"Snell's Law","input":[{"name":"n1","unit":"scalar"},{"name":"n2","unit":"scalar"},{"name":"theta1","unit":"degree"}],"output":{"name":"theta2","unit":"degree"},"d4rtCode":"var theta1Rad = theta1 * (pi / 180); var sinTheta2 = (n1 * sin(theta1Rad)) / n2; theta2 = asin(sinTheta2) * (180 / pi);","tags":["physics","optics","light"]}
|
||||||
Law describing refraction of light at an interface between two media.
|
|
||||||
|
|
||||||
$$n_1 \sin(\theta_1) = n_2 \sin(\theta_2)$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $n_1, n_2$: Refractive indices
|
|
||||||
- $\theta_1$: Angle of incidence
|
|
||||||
- $\theta_2$: Angle of refraction
|
|
||||||
|
|
||||||
This law explains how light bends when passing between materials.
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"n1","unit":"scalar"},{"name":"n2","unit":"scalar"},{"name":"theta1","unit":"degree"}],"output":{"name":"theta2","unit":"degree"},"d4rtCode":"var theta1Rad = theta1 * (pi / 180); var sinTheta2 = (n1 * sin(theta1Rad)) / n2; theta2 = asin(sinTheta2) * (180 / pi);","tags":["physics","optics","light"]}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,2 @@
|
||||||
[
|
[
|
||||||
{"name":"Ideal Gas Law","description":r"""
|
|
||||||
Equation of state for an ideal gas.
|
|
||||||
|
|
||||||
$$PV = nRT$$
|
|
||||||
|
|
||||||
Where:
|
|
||||||
- $P$: Pressure (Pascals)
|
|
||||||
- $V$: Volume (m^3)
|
|
||||||
- $n$: Amount of substance (moles)
|
|
||||||
- $R$: Universal gas constant $8.314\ \mathrm{J/(mol\cdot K)}$
|
|
||||||
- $T$: Temperature (Kelvin)
|
|
||||||
|
|
||||||
This law combines Boyle's, Charles's and Avogadro's laws.
|
|
||||||
|
|
||||||

|
|
||||||
""","input":[{"name":"n","unit":"mole"},{"name":"T","unit":"kelvin"},{"name":"V","unit":"cubic meter"}],"output":{"name":"P","unit":"pascal"},"d4rtCode":"P = (n * 8.314462618 * T) / V;","tags":["physics","thermodynamics","gas"]}
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
[
|
||||||
|
]
|
||||||
|
|
@ -52,10 +52,20 @@ Future<Corpus> createDefaultCorpus() async{
|
||||||
Future<void> loadFormulas() async {
|
Future<void> loadFormulas() async {
|
||||||
final formulaResources = [
|
final formulaResources = [
|
||||||
"assets/formulas/formulas.d4rt",
|
"assets/formulas/formulas.d4rt",
|
||||||
|
"assets/formulas/conversions_and_constants.d4rt",
|
||||||
"assets/formulas/electromagnetism.d4rt",
|
"assets/formulas/electromagnetism.d4rt",
|
||||||
"assets/formulas/thermodynamics.d4rt",
|
"assets/formulas/energy_and_power.d4rt",
|
||||||
"assets/formulas/fluids_and_pressure.d4rt",
|
"assets/formulas/fluids_and_pressure.d4rt",
|
||||||
|
"assets/formulas/geometry.d4rt",
|
||||||
|
"assets/formulas/gravity.d4rt",
|
||||||
|
"assets/formulas/it-networking.d4rt",
|
||||||
|
"assets/formulas/kinematics_and_dynamics.d4rt",
|
||||||
|
"assets/formulas/materials_elasticity.d4rt",
|
||||||
|
"assets/formulas/medical_and_bio.d4rt",
|
||||||
|
"assets/formulas/misc_math.d4rt",
|
||||||
|
"assets/formulas/optics.d4rt",
|
||||||
|
"assets/formulas/thermodynamics.d4rt",
|
||||||
|
"assets/formulas/trigonometry.d4rt",
|
||||||
];
|
];
|
||||||
|
|
||||||
for (final formRes in formulaResources) {
|
for (final formRes in formulaResources) {
|
||||||
|
|
@ -63,6 +73,7 @@ Future<Corpus> createDefaultCorpus() async{
|
||||||
final literal = await loadResourceAsString(formRes);
|
final literal = await loadResourceAsString(formRes);
|
||||||
print( "Loaded $formRes");
|
print( "Loaded $formRes");
|
||||||
final formulas = Formula.fromArrayStringLiteral(literal);
|
final formulas = Formula.fromArrayStringLiteral(literal);
|
||||||
|
print( "Parsed $formRes");
|
||||||
final formulaElements = formulas.cast<FormulaElement>();
|
final formulaElements = formulas.cast<FormulaElement>();
|
||||||
corpus.loadFormulaElements(formulaElements);
|
corpus.loadFormulaElements(formulaElements);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:d4rt_formulas/d4rt_formulas.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'database/database_service.dart';
|
import 'database/database_service.dart';
|
||||||
import 'package:drift/drift.dart' as drift;
|
import 'package:drift/drift.dart' as drift;
|
||||||
|
|
@ -92,9 +93,9 @@ Future<Corpus> loadCorpusFromDatabaseOrAssets() async {
|
||||||
// Load corpus from database elements
|
// Load corpus from database elements
|
||||||
return await Corpus.fromDatabaseElements(dbElements);
|
return await Corpus.fromDatabaseElements(dbElements);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e, st) {
|
||||||
// If there's an error loading from database, fall back to default corpus
|
// If there's an error loading from database, fall back to default corpus
|
||||||
print('Error loading corpus from database: $e');
|
errorHandler.notify(e,st);
|
||||||
return await createDefaultCorpus();
|
return await createDefaultCorpus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue