Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
observation.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2018 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 /*
17  * observation.h
18  *
19  * Created on: 30 Oct 2018
20  * Author: billy
21  */
22 
23 #ifndef SERVICES_FIELD_TRIALS_INCLUDE_OBSERVATION_H_
24 #define SERVICES_FIELD_TRIALS_INCLUDE_OBSERVATION_H_
25 
28 #include "measured_variable.h"
29 
30 
31 
32 typedef enum ObservationType
33 {
40 
41 typedef enum ObservationNature
42 {
43  ON_UNSET = -1,
48 
49 
51 {
55 
56 
63 typedef struct Observation
64 {
65  bson_oid_t *ob_id_p;
66 
71  struct tm *ob_start_date_p;
72 
77  struct tm *ob_end_date_p;
78 
83 
84 
86 
88 
93 
94  char *ob_method_s;
95 
96 
100  char *ob_notes_s;
101 
102 
104 
114  uint32 ob_index;
115 
116 
118 
119 
120  void (*ob_clear_fn) (struct Observation *observation_p);
121 
122  bool (*ob_add_values_to_json_fn) (const struct Observation *obs_p, const char *raw_key_s, const char *corrected_key_s, json_t *json_p, const char *null_sequence_s, bool only_if_exists_flag);
123 
124  bool (*ob_set_value_from_json_fn) (struct Observation *observation_p, ObservationValueType ovt, const json_t *value_p);
125 
126  bool (*ob_set_value_from_string_fn) (struct Observation *observation_p, ObservationValueType ovt, const char *value_s);
127 
128  bool (*ob_get_value_as_string_fn) (struct Observation *observation_p, ObservationValueType ovt, char **value_ss, bool *free_value_flag_p);
129 
130 } Observation;
131 
132 
133 typedef struct ObservationNode
134 {
136 
139 
140 
141 
142 #ifndef DOXYGEN_SHOULD_SKIP_THIS
143 
144 #ifdef ALLOCATE_OBSERVATION_TAGS
145  #define OBSERVATION_PREFIX DFW_FIELD_TRIAL_SERVICE_LOCAL
146  #define OBSERVATION_VAL(x) = x
147  #define OBSERVATION_CONCAT_VAL(x,y) = x y
148 #else
149  #define OBSERVATION_PREFIX extern
150  #define OBSERVATION_VAL(x)
151  #define OBSERVATION_CONCAT_VAL(x,y)
152 #endif
153 
154 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
155 
156 
157 OBSERVATION_PREFIX const char *OB_PHENOTYPE_S OBSERVATION_VAL ("phenotype");
158 
159 OBSERVATION_PREFIX const char *OB_PHENOTYPE_ID_S OBSERVATION_VAL ("phenotype_id");
160 
161 OBSERVATION_PREFIX const char *OB_START_DATE_S OBSERVATION_VAL ("date");
162 
163 OBSERVATION_PREFIX const char *OB_END_DATE_S OBSERVATION_VAL ("end_date");
164 
165 OBSERVATION_PREFIX const char *OB_RAW_VALUE_S OBSERVATION_VAL ("raw_value");
166 
167 OBSERVATION_PREFIX const char *OB_INSTRUMENT_ID_S OBSERVATION_VAL ("instrument_id");
168 
169 OBSERVATION_PREFIX const char *OB_INSTRUMENT_S OBSERVATION_VAL ("instrument");
170 
171 OBSERVATION_PREFIX const char *OB_GROWTH_STAGE_S OBSERVATION_VAL ("growth_stage");
172 
173 OBSERVATION_PREFIX const char *OB_CORRECTED_VALUE_S OBSERVATION_VAL ("corrected_value");
174 
175 OBSERVATION_PREFIX const char *OB_METHOD_S OBSERVATION_VAL ("method");
176 
177 OBSERVATION_PREFIX const char *OB_NATURE_S OBSERVATION_VAL ("nature");
178 
179 OBSERVATION_PREFIX const char *OB_INDEX_S OBSERVATION_VAL ("index");
180 
181 
182 OBSERVATION_PREFIX const char *OB_TYPE_S OBSERVATION_VAL ("value_type");
183 
184 OBSERVATION_PREFIX const char *OB_NOTES_S OBSERVATION_VAL ("notes");
185 
186 OBSERVATION_PREFIX const uint32 OB_DEFAULT_INDEX OBSERVATION_VAL (1);
187 
188 
189 #ifdef __cplusplus
190 extern "C"
191 {
192 #endif
193 
194 
195 
196 DFW_FIELD_TRIAL_SERVICE_LOCAL Observation *AllocateObservation (bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p,
197  MEM_FLAG phenotype_mem, const json_t *raw_value_p, const json_t *corrected_value_p,
198  const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature,
199  const uint32 *index_p, const char *notes_s, const ObservationType obs_type);
200 
201 DFW_FIELD_TRIAL_SERVICE_LOCAL Observation *AllocateObservationWithErrorHandler (bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p,
202  MEM_FLAG phenotype_mem, const json_t *raw_value_p, const json_t *corrected_value_p,
203  const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature,
204  const uint32 *index_p, const char *notes_s, const ObservationType obs_type,
205  void (*on_error_callback_fn) (ServiceJob *job_p, const char * const observation_field_s, const void *value_p, void *user_data_p),
206  ServiceJob *job_p, void *user_data_p);
207 
208 DFW_FIELD_TRIAL_SERVICE_LOCAL bool InitObservation (Observation *observation_p, bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p, MEM_FLAG phenotype_mem,
209  const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature, const uint32 *index_p, const char *notes_s, const ObservationType obs_type,
210  void (*clear_fn) (Observation *observation_p),
211  bool (*add_values_to_json_fn) (const struct Observation *obs_p, const char *raw_key_s, const char *corrected_key_s, json_t *json_p, const char *null_sequence_s, bool only_if_exists_flag),
212  bool (*set_value_from_json_fn) (struct Observation *observation_p, ObservationValueType ovt, const json_t *value_p),
213  bool (*set_value_from_string_fn) (struct Observation *observation_p, ObservationValueType ovt, const char *value_s),
214  bool (*get_value_as_string_fn) (struct Observation *observation_p, ObservationValueType ovt, char **value_ss, bool *free_value_flag_p)
215 );
216 
217 
218 
226 
227 
235 
236 
245 
246 
255 
256 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetObservationAsJSON (const Observation *observation_p, const ViewFormat format);
257 
259 
261 
262 
271 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AreObservationsMatching (const Observation *observation_0_p, const Observation *observation_1_p);
272 
273 
274 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AreObservationsMatchingByParts (const Observation *observation_p, const MeasuredVariable *variable_p, const struct tm *start_date_p, const struct tm *end_date_p, const uint32 *index_p);
275 
276 
278 
279 
280 DFW_FIELD_TRIAL_SERVICE_LOCAL bool DetermineObservationTypeFromString (const char * const obs_type_s, ObservationType *obs_type_p);
281 
282 
283 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetObservationRawValueFromString (Observation *observation_p, const char * const value_s);
284 
285 
286 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetObservationCorrectedValueFromString (Observation *observation_p, const char * const value_s);
287 
288 
289 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetObservationRawValueFromJSON (Observation *observation_p, const json_t *value_p);
290 
291 
292 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetObservationCorrectedValueFromJSON (Observation *observation_p, const json_t *value_p);
293 
294 
296 
297 
299 
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 
306 
307 #endif /* SERVICES_FIELD_TRIALS_INCLUDE_OBSERVATION_H_ */
GetObservationFromJSON
Observation * GetObservationFromJSON(const json_t *phenotype_json_p, FieldTrialServiceData *data_p)
ObservationValueType
ObservationValueType
Definition: observation.h:50
ObservationNode::on_observation_p
Observation * on_observation_p
Definition: observation.h:137
Observation::ob_growth_stage_s
char * ob_growth_stage_s
Definition: observation.h:92
Observation::ob_method_s
char * ob_method_s
Definition: observation.h:94
SetObservationRawValueFromJSON
bool SetObservationRawValueFromJSON(Observation *observation_p, const json_t *value_p)
AreObservationsMatchingByParts
bool AreObservationsMatchingByParts(const Observation *observation_p, const MeasuredVariable *variable_p, const struct tm *start_date_p, const struct tm *end_date_p, const uint32 *index_p)
Instrument
Definition: instrument.h:33
Observation::ob_set_value_from_string_fn
bool(* ob_set_value_from_string_fn)(struct Observation *observation_p, ObservationValueType ovt, const char *value_s)
Definition: observation.h:126
MEM_FLAG
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:38
SaveObservation
bool SaveObservation(Observation *observation_p, const FieldTrialServiceData *data_p)
ServiceJob
A datatype to represent a running task.
Definition: service_job.h:72
measured_variable.h
AreObservationsMatching
bool AreObservationsMatching(const Observation *observation_0_p, const Observation *observation_1_p)
Test whether two Observations are the same in terms of phenotypes, dates and observation indexes.
ObservationNode::on_node
ListItem on_node
Definition: observation.h:135
SetObservationCorrectedValueFromJSON
bool SetObservationCorrectedValueFromJSON(Observation *observation_p, const json_t *value_p)
Observation::ob_type
ObservationType ob_type
Definition: observation.h:117
Observation::ob_phenotype_p
MeasuredVariable * ob_phenotype_p
The MeasuredVariable that this Observation is measuring.
Definition: observation.h:82
GetObservationTypeAsString
const char * GetObservationTypeAsString(const ObservationType obs_type)
SetObservationRawValueFromString
bool SetObservationRawValueFromString(Observation *observation_p, const char *const value_s)
Observation::ob_clear_fn
void(* ob_clear_fn)(struct Observation *observation_p)
Definition: observation.h:120
Observation::ob_phenotype_mem
MEM_FLAG ob_phenotype_mem
Definition: observation.h:85
Observation::ob_get_value_as_string_fn
bool(* ob_get_value_as_string_fn)(struct Observation *observation_p, ObservationValueType ovt, char **value_ss, bool *free_value_flag_p)
Definition: observation.h:128
AllocateObservationNode
ObservationNode * AllocateObservationNode(Observation *observation_p)
Allocate an ObservationNode for a given Observation.
dfw_field_trial_service_library.h
DetermineObservationTypeFromString
bool DetermineObservationTypeFromString(const char *const obs_type_s, ObservationType *obs_type_p)
OT_NUMERIC
Definition: observation.h:34
OT_STRING
Definition: observation.h:35
OVT_CORRECTED_VALUE
Definition: observation.h:53
ON_EXPERIMENTAL_AREA
Definition: observation.h:45
Observation::ob_start_date_p
struct tm * ob_start_date_p
The date and time when the measuring for this Observation was started.
Definition: observation.h:71
AddObservationValuesToFrictionlessData
bool AddObservationValuesToFrictionlessData(Observation *obs_p, json_t *fd_json_p)
FreeObservation
void FreeObservation(Observation *observation_p)
Free an Observation.
DFW_FIELD_TRIAL_SERVICE_LOCAL
#define DFW_FIELD_TRIAL_SERVICE_LOCAL
Definition: dfw_field_trial_service_library.h:43
MeasuredVariable
Definition: measured_variable.h:39
Observation::ob_end_date_p
struct tm * ob_end_date_p
The date and time when the measuring for this Observation was started.
Definition: observation.h:77
DFW_FIELD_TRIAL_SERVICE_API
#define DFW_FIELD_TRIAL_SERVICE_API
Definition: dfw_field_trial_service_library.h:42
ON_NUM_PHENOTYPE_NATURES
Definition: observation.h:46
Observation::ob_index
uint32 ob_index
For some phenotype data multiple data points are taken from the same plot e.g.
Definition: observation.h:114
Observation::ob_id_p
bson_oid_t * ob_id_p
Definition: observation.h:65
AllocateObservationWithErrorHandler
Observation * AllocateObservationWithErrorHandler(bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p, MEM_FLAG phenotype_mem, const json_t *raw_value_p, const json_t *corrected_value_p, const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature, const uint32 *index_p, const char *notes_s, const ObservationType obs_type, void(*on_error_callback_fn)(ServiceJob *job_p, const char *const observation_field_s, const void *value_p, void *user_data_p), ServiceJob *job_p, void *user_data_p)
FreeObservationNode
void FreeObservationNode(ListItem *node_p)
Free an ObservationNode.
ClearObservation
void ClearObservation(Observation *observation_p)
Clear the data stored within an Observation.
OBSERVATION_VAL
const OBSERVATION_PREFIX char *OB_PHENOTYPE_S OBSERVATION_VAL("phenotype")
Observation::ob_add_values_to_json_fn
bool(* ob_add_values_to_json_fn)(const struct Observation *obs_p, const char *raw_key_s, const char *corrected_key_s, json_t *json_p, const char *null_sequence_s, bool only_if_exists_flag)
Definition: observation.h:122
ON_ROW
Definition: observation.h:44
ON_UNSET
Definition: observation.h:43
dfw_field_trial_service_data.h
Observation::ob_set_value_from_json_fn
bool(* ob_set_value_from_json_fn)(struct Observation *observation_p, ObservationValueType ovt, const json_t *value_p)
Definition: observation.h:124
ObservationNature
ObservationNature
Definition: observation.h:41
SetObservationCorrectedValueFromString
bool SetObservationCorrectedValueFromString(Observation *observation_p, const char *const value_s)
OT_INTEGER
Definition: observation.h:36
GetObservationAsJSON
json_t * GetObservationAsJSON(const Observation *observation_p, const ViewFormat format)
GetObservationTypeForScaleClass
ObservationType GetObservationTypeForScaleClass(const ScaleClass *class_p)
Observation
A datatype for storing a phneotypic observation within an experiment.
Definition: observation.h:63
Observation::ob_instrument_p
Instrument * ob_instrument_p
Definition: observation.h:87
OT_NUM_TYPES
Definition: observation.h:38
ScaleClass
Definition: dfw_field_trial_service_data.h:105
OT_TIME
Definition: observation.h:37
FieldTrialServiceData
The configuration data used by the DFW Field Trial Service.
Definition: dfw_field_trial_service_data.h:118
Observation::ob_nature
ObservationNature ob_nature
Definition: observation.h:103
ViewFormat
ViewFormat
An indicator of what the output destination is for the JSON data values.
Definition: view_format.h:19
AllocateObservation
Observation * AllocateObservation(bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p, MEM_FLAG phenotype_mem, const json_t *raw_value_p, const json_t *corrected_value_p, const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature, const uint32 *index_p, const char *notes_s, const ObservationType obs_type)
Observation::ob_notes_s
char * ob_notes_s
Any notes about this observation.
Definition: observation.h:100
ObservationNode
Definition: observation.h:133
InitObservation
bool InitObservation(Observation *observation_p, bson_oid_t *id_p, const struct tm *start_date_p, const struct tm *end_date_p, MeasuredVariable *phenotype_p, MEM_FLAG phenotype_mem, const char *growth_stage_s, const char *method_s, Instrument *instrument_p, const ObservationNature nature, const uint32 *index_p, const char *notes_s, const ObservationType obs_type, void(*clear_fn)(Observation *observation_p), bool(*add_values_to_json_fn)(const struct Observation *obs_p, const char *raw_key_s, const char *corrected_key_s, json_t *json_p, const char *null_sequence_s, bool only_if_exists_flag), bool(*set_value_from_json_fn)(struct Observation *observation_p, ObservationValueType ovt, const json_t *value_p), bool(*set_value_from_string_fn)(struct Observation *observation_p, ObservationValueType ovt, const char *value_s), bool(*get_value_as_string_fn)(struct Observation *observation_p, ObservationValueType ovt, char **value_ss, bool *free_value_flag_p))
OVT_RAW_VALUE
Definition: observation.h:52
ListItem
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43
ObservationType
ObservationType
Definition: observation.h:32