valueflows

valueflows docs
git clone https://s.sonu.ch/~srfsh/valueflows.git
Log | Files | Refs | README

dhen-value-flow.md (4923B)


      1 #DHen value flow
      2 
      3 [value flow report](http://dhen.webfactional.com/accounting/resource-flow-report/14/)
      4 
      5 *(That's a table, we want a set of mini Sankey diagrams...)*
      6 
      7 An example of an incoming value flow combining Exchanges and Processes. The numbers on the left are depth in a depth-first search starting from the end resource (pseudocode below).
      8 
      9 ```
     10   0 EconomicResource: Catnip: 60915
     11  . 1 EconomicEvent: Transfer 2015-06-20 from Namaste Lane Gardens to Tea for the People 0.89 Lbs Catnip: 60915
     12  .. 2 Exchange: Transfer Catnip
     13  .. 2 EconomicEvent: Resource Production 2015-06-09 12.41 Lbs Catnip: 60915
     14  ... 3 Process: Combined harvested: new lot  starting 2015-06-09 ending 2015-06-09
     15  .... 4 EconomicEvent: Resource Consumption 2015-06-09 8.19 Lbs Catnip: Catnip from farm
     16  .... 4 EconomicEvent: Resource Consumption 2015-06-09 4.22 Lbs Catnip: Catnip from farm
     17  ..... 5 EconomicResource: Catnip: Catnip from farm2
     18  ...... 6 EconomicEvent: Transfer 2015-06-09 from Megan Pierce to Namaste Lane Gardens 8.19 Lbs Catnip: Catnip from farm2
     19  ....... 7 Exchange: Transfer Catnip
     20  ....... 7 EconomicEvent: Receipt 2015-06-09 from Dancing Waters Permaculture Coop to Megan Pierce 8.19 Lbs Catnip: Catnip from farm2
     21  ........ 8 Exchange: Purchase Catnip
     22  ..... 5 EconomicResource: Catnip: Catnip from farm1
     23  ...... 6 EconomicEvent: Transfer 2015-06-09 from Lauren McElroy to Namaste Lane Gardens 4.22 Lbs Catnip: Catnip from farm1
     24  ....... 7 Exchange: Transfer Catnip
     25  ....... 7 EconomicEvent: Receipt 2015-06-09 from Dancing Waters Permaculture Coop to Lauren McElroy 4.22 Lbs Catnip: Catnip from farm1
     26  ........ 8 Exchange: Purchase Catnip
     27 ```
     28 ### Agents involved
     29 
     30 * Dancing Waters Permaculture Coop (group running the harvesting site, aka farm)
     31 * Megan Pierce (person harvesting)
     32 * Lauren McElroy (person harvesting)
     33 * Namaste Lane Gardens (group running the drying site)
     34 * Tea for the People (group selling the product)
     35 
     36 ### Detailed explaination
     37 
     38 What's going on here, from beginning of flow to end (note only the catnip flow is displayed, nothing of reverse flows):
     39 * Megan and Lauren both harvested catnip at Dancing Waters farm. (Process not recorded, no need.)
     40 * There is a transfer from DW to each of them so they now own the catnip. (This is the 7 receipt, 8 exchange. They could pay the farm as part of this exchange, but in this case, they don't bother because they both live there.  And often the farms donate the herbs anyhow.)
     41 * They each sold the catnip to Namaste Lane. (7 transfer, 6, 5. Two exchanges - only the transfer (receipt by NL) of the herbs shows in this directional sequence, the harvesters are either paid or owed money.)
     42 * Namaste Lane combined the catnip into one lot and put it into the drying room (a process 3, with inputs 4 and 4, and output 2 resource production - this is where the lot number is created)
     43 * When it got dry, it was removed from the drying room.  (Process not recorded.)
     44 * When it comes out though, it also changes ownership - transfered from NL to Tea for People.  Still has the same lot number, but much less weight because it is dry. (Exchange 2 Transfer, and 1. Now it is just sitting in a storage room waiting to be sold.  Again reverse side of the exchange not shown.)
     45 
     46 ###Sequencing the flows (pseudocode):
     47 
     48 ```
     49 resource = Catnip: 60915:
     50 resource.depth_first_search():
     51     events = resource.all_economic_events()
     52     data = {} #a dictionary
     53     for event in events:
     54         prevs = event.previous_events() (which is not generally correct yet - more below)
     55         data[event] = prevs
     56     # Sequence events via topological sort, 
     57     # starting from events with no previous_events,
     58     # following the chain from previous to next event.
     59     event_sequence = toposort(data) 
     60     event_sequence.reverse()
     61     for event in event_sequence:
     62         if event.is_transfer():
     63             follow from transfer to exchange to reciprocal_transfer
     64         elif event.is_production():
     65             for input in event.process.inputs():
     66                 input.resource.depth_first_search()
     67                 
     68         
     69 ```
     70 
     71 ## Actual code
     72 
     73 (These links will become obsolete soon...will either delete or do something better...)
     74 
     75 * [incoming_value_flows](https://github.com/valnet/valuenetwork/blob/master/valuenetwork/valueaccounting/models.py#L4708)
     76 * [calls a recursive depth-first-search](https://github.com/valnet/valuenetwork/blob/master/valuenetwork/valueaccounting/models.py#L4729)
     77     * [calls event_sequence](https://github.com/valnet/valuenetwork/blob/master/valuenetwork/valueaccounting/models.py#L3842)
     78         * [calls event.previous_events](https://github.com/valnet/valuenetwork/blob/master/valuenetwork/valueaccounting/models.py#L8543) which is a temporary hack awaiting ExchangeType recipes
     79         * [calls a topological sort](https://bitbucket.org/ericvsmith/toposort/src/25b5894c4229cb888f77cf0c077c05e2464446ac/toposort.py?at=default&fileviewer=file-view-default)