Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

fr:specs:workflows [2016/08/26 21:06] (Version actuelle)
Ligne 1: Ligne 1:
 +====== Workflow ======
  
 +<code yaml>
 +workflow:
 +  name: spraying
 +  types:
 +    MedicineProduct:​ Product(roles:​ "​plant_illness_treatment-input_origin"​)
 +    MedicineQuantity:​ Measure(unit:​ :kg, roles: "​plant_illness_treatment-input_quantity"​)
 +    MedicineDose:​ Struct(product:​ MedicineProduct,​ quantity: MedicineQuantity)
 +    Sprayed: Struct(product:​ Product(), zone: MultiPolygon())
 +  variables:
 +    intrants: IN List(type: MedicineDose,​ min: 1)
 +    driver: IN Entity(roles:​ "​plant_illness_treatment-doer",​ filter: "​can(drive)"​)
 +    sprayed: IN List(type: Sprayed, min: 1)
 +    tractor: IN Product(filter:​ "can tow(sprayer) and can move"
 +    sprayer: IN Product(filter:​ "can spray(matter)"​)
 +    remaining: OUT Medicine
 +    mixture: Medicine
 +  run:
 +    # Prepare fixture
 +    if size(intrants) > 1
 +      call-workflow :mixing
 +        products: intrants
 +        mixture: mixture
 +    else
 +      call-workflow :separation
 +        product: attr(nth(intrants,​ 1), :product)
 +        quantity: attr(nth(intrants,​ 1), :quantity)
 +        part: mixture ​      
 +    # Load it
 +    call-workflow :loading
 +      product: mixture
 +      container: sprayer
 +    # Spray it
 +    assign(total,​ 0)
 +    each(sprayeds,​ sprayed)
 +      assign(total,​ total + get(attr(sprayed,​ :product), info: :​net_surface_area,​ unit: :ha))
 +    each(sprayeds,​ sprayed)
 +      if ask goto_to_sprayed?​
 +        call-workflow :movement
 +          object: tractor
 +          destination:​ attr(sprayed,​ :product)
 +      ​
 +      product_consumption(sprayed,​ mixture, quantity)
 +      ​
 +</​code>​
 +
 +
 +<code xml>
 +<​workflow name="​sowing"​ nature="​sowing">​
 +  <​variables>​
 +    <​variable name="​seeds" ​ type="​product"​ working-expr="​is seed and derives from plant and can grow" dir="​in"​ roles="​sowing-input_origin"/>​
 +    <​variable name="​quantity_to_sow"​ type="​measure"​ dimension="​mass"​ unit="​kg"​ dir="​in"​ default-value="​seeds.net_mass">​
 +      <handler type="​measure"​ dimension="​mass"​ unit="​t"​
 +               ​forward="​value * 1000"
 +               ​backward="​value / 1000"
 +               />
 +      <handler type="​measure"​ dimension="​mass_area_density"​ unit="​kg/​ha"  ​
 +               ​forward="​value * zone_to_sow.area(hectare)"​
 +               ​backward="​value / zone_to_sow.area(hectare)"​
 +               />
 +      <handler type="​measure"​ unit="​./​m²"​ if="​seeds has indicator thousand_grain_mass" ​
 +               ​forward="​(((value * self.thousand_grains_mass(gram)) / 1000) * cultivation.net_surface_area(square_meter))"​
 +               ​backward="​value / zone_to_sow.area(hectare)"​
 +               /> ​              
 +      <handler type="​measure"​ unit="​k."  ​
 +               ​forward="​(value * self.thousand_grains_mass(gram)) / 1000"
 +               ​backward="​(value * 1000) / self.thousand_grains_mass(gram)"​
 +               />
 +      <​validator type="​less-than"​ value="​seeds.population.in()"/>​
 +    </​variable>​
 +    <​variable name="​seeds_to_sow"​ type="​product"/>​
 +    <​variable name="​sower" ​       type="​product"​ working-expr="​can sow" dir="​in"/>​
 +    <​variable name="​tractor" ​     type="​product"​ working-expr="​can tow(sower) and can move" dir="​in"/>​
 +    <​variable name="​land_parcel" ​ type="​product"​ working-expr="​can tow(equipment) and can move" dir="​in"/>​
 +    <​variable name="​zone_to_sow" ​ type="​multipolygon"​ default-value="​land_parcel.shape"​ dir="​in"/>​
 +    <​variable name="​cultivation" ​ type="​product"/>​
 +  </​variables>​
 +  <​operations>​
 +    <if test="​my_value &gt; 10kg">​
 +      <log level="​info">​Weight > #{10kg - 1mg}</​log>​
 +      <​call-function name="​product-consumption">​
 +      </​call-function>​
 +    </if>
 +    <​call-function name="​product-division">​
 +      <param name="​producer">​seeds</​param>​
 +      <param name="​produced">​seeds_to_sow</​param>​
 +      <param name="​producer">​quantity</​param> ​     ​
 +    </​call-function>​
 +    <​call-function name="​send-email">​
 +      <param name="​recipient">"​contact@ekylibre.org"</​param>​
 +      <param name="​message">"​Work is done."</​param>​
 +    </​call-function>​
 +  </​operations>​
 +</​workflow>​
 +</​code>​
 +
 +
 +<​code>​
 +integer toto = 145.2
 +measure toto = 12.3kg
 +
 +if my_value > 10kg
 +  log(:info, "​Weight > #{10kg - 1mg}")
 +  product-consumption(grass,​ cow, quantity)
 +  ​
 +end
 +
 +send-email("​contact@ekylibre.org",​ "Hello world !\n")
 +</​code>​