Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Capture precipitation rain/snow by day #57

Open
woodbri opened this issue Jul 9, 2018 · 7 comments
Open

Capture precipitation rain/snow by day #57

woodbri opened this issue Jul 9, 2018 · 7 comments

Comments

@woodbri
Copy link
Collaborator

woodbri commented Jul 9, 2018

Capture precipitation rain/snow by day

  • summarize into 5 day buckets in plan

I think we discussed a more generalized weather module in #3

from #3 #39

@mstenta
Copy link
Member

mstenta commented Jul 10, 2018

This could be a simple quick form that creates observation logs with a "Weather" category.

@woodbri woodbri added this to the Sprint 5 milestone Jul 10, 2018
@woodbri
Copy link
Collaborator Author

woodbri commented Jul 10, 2018

Add quick form to capture this data

@mstenta
Copy link
Member

mstenta commented Jul 10, 2018

(copied from my duplicate issue:)

Add a simple quick form for recording observations of rain/snow fall, and how much. This could be the first feature of a new farm_weather module in farmOS core.

@mstenta
Copy link
Member

mstenta commented Aug 1, 2018

I started a new Weather module: https://github.com/mstenta/farm_weather

It provides a "Weather" log category - that's all it does right now.

Here is the issue specifically for the quick form: farmOS/farm_weather#2

@mstenta
Copy link
Member

mstenta commented Aug 3, 2018

Done.

@mstenta mstenta closed this as completed Aug 3, 2018
@woodbri
Copy link
Collaborator Author

woodbri commented Aug 22, 2018

Please add example code how to query these observations

@woodbri woodbri reopened this Aug 22, 2018
@mstenta
Copy link
Member

mstenta commented Sep 5, 2018

I added a new function to farmOS specifically for querying+loading logs with quantity data on them: farm_quantity_log()

Here is how you would use that to load rain and snow precipitation observation logs created by the new quick form:

// The function optionally takes a $start_time and $end_time (UNIX timestamps) to limit to a range of logs. If omitted, all logs will be included.
$start_time = strtotime('2018-08-01');
$end_time = strtotime('2018-08-31');

// The quick form creates quantities with a measure of 'length'. It's good to include this as a filter now, because we may add additional quantities to the form in the future (such as 'temperature' - see https://github.com/farmOS/farm_weather/issues/5).
$measure = 'length';

// The quick form adds a label of 'rain' or 'snow' to the quantity measurements, depending on what is selected in the form. Note that you need to query these separately.
$label = 'rain';
// $label = 'snow';

// Limit to logs that are done.
$done = TRUE;

// The weather quick form creates observation logs.
$log_type = 'farm_observation';

// Limit to logs in the "Weather" category.
$category = 'Weather';

// Load all matching quantity logs.
$logs = farm_quantity_log($measure, $label, $start_time, $end_time, $done, $log_type, $category);

With that array of $logs, you can use the farm_quantity_log_data() function to extract specific information from the log, like so:

foreach ($logs as $log) {
  $data = farm_quantity_log_data($log, 'length', 'rain');
}

This will give you an array like this:

$data = array(
  array(
    'measure' => 'length',
    'value' => '4',
    'units' => 'inches',
    'label' => 'rain',
  )
);

(Note that it is an array of arrays, because technically logs can contain multiple measurements. The weather quick form currently only adds a single measurement.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants