mirror_farmos
v0.6.2
Published
Tools aimed at creating and keeping a farmOS mirror up to date, currently focused on mongoDB hosting. There are also extensive tools for data dereferencing, consolidation and simplification.
Downloads
1
Readme
Introduction
The objective of the mongo_mirror
is to centralize, transform and serve data from a huge number of discrete and private farmOS instances into a unified, fast, efficient, privacy respectful and versatile database.
A mirror allows data operations that would be overly costly, time consuming and privacy harming if done instancywise.
This library provides a very simple interface that will allow a mirror to be built from scratch by only providing the adequate security keys and some variables describing the expected behaviour. As the farmOS data structure is fiarly complex to be directly consumed by some applications, this library is also able to consolidate it and de reference it into structures that are as flat as possible without loosing data content or precission. This also makes data analysis easier.
The mongo_mirror
can optionally supervise the application of as many data pipelines as needed to be applied over this consolidated and simplified dataset, in order to deliver the exact data that each applicatino needs. For example, a first dataset might only have anonimized GPS positions to show in a map the farms
How this library works
Transformations Applied to Entities
Entities are mirrored inside a tree structure before dereferencing.
Each entity gets a field called
related
. It contains the entities mentioned inrelations
. Each one of this entities contains its ownrelated
field, the entities look the same when searched directly or as relationships of other related entities.Entities inside
related
are tagged with arelationship_class
attribute. It informs under whichrelations
attribute it was originally stored and allows to distinguis what kind of information should be obtained from it.I traversed the FarmOs UI and identified the source (either an attribute on the main entity or inside a relationship) for each bit of data that is shown there for each type of entity. These are copied into the main entity with appropiate data names as first level object properties, obtained either from
attributes
on the original main entity or inside any of its related sub entities.
Modules
Nightly Build
Meant to grab information from FarmOS instances and centralize it into a MongoDB unique database.
Main Functions
copyFarmToMongo
: Provided a farm and a list of types, all entitities for each type are retrieved, tagged with the adequatefarmDomain
attribute and stored insideraw_entities
collection.copyManyFarmsToMongo
: Helps iterate through the whole list of farms.
Dereference and Simplify
Meant to reformat the data into a consolidated, as flat as possible without loosing details planting centric database.
It assembles whole objects based on FarmOS references attributes so that each object contains directly all of its related information.
It employs a set of parsers called Instructions
to grab only the data attributes that are relevant from each entity and arrange them in the most possible meaningful way without making wrong structure assumptions.
processOneFarm
retrieves all entities fromraw_entities
for a given farm, dereferences them, simplifies them and copies them intosimplified_entities
.
Coffeeshop Aggregations
Not currently a library.
An aggregation grabs plantings from simplified_entities
, attaches events (as they are reverse dependencies) and consolidates planting rows into coffeeshop_full
. This is further simplified and stored as coffeeshop_simplified
, which is the exact payload the coffeeshop frontend expects.