save hep nest data

pull/1/head
Angelo DiNardi 3 years ago
parent 872cec222a
commit a64629a061
  1. 51
      app.py
  2. 2
      datasheet.jsx
  3. 17
      load.sql

@ -92,12 +92,13 @@ def save_sheet():
end_time = str(data['endTime'])
nest_visibility = str(data['nestVisibility'])
visibility_comments = str(data['visibilityComments'])
survey_summary = data['surveySummary']
survey_summary = data['surveySummary'] # type: dict
significant_changes = bool(data['colonySignificantChanges'])
significant_changes_notes = str(data['colonySignificantChangesNotes'])
human_disturbance = bool(data['colonyHumanDisturbance'])
human_disturbance_notes = str(data['colonyHumanDisturbanceNotes'])
additional_observations = str(data['colonyAdditionalObservations'])
hep_nest_data = data['hepNestData'] # type: list
with get_db() as db:
with db.cursor() as cur:
@ -180,5 +181,53 @@ def save_sheet():
'total_possible_nests': total_possible_nests,
})
for item in hep_nest_data:
number = int(item['number'])
is_focal = bool(item['isFocal'])
species_code = str(item['speciesCode'])
active = str(item['active'])
stage = int(item['stage'])
adult_count = int(item['adultCount'])
chick_count = int(item['chickCount'])
chick_confidence = bool(item['chickConfidence'])
comments = str(item['comments'])
cur.execute("""
INSERT INTO hep_nest_data (
data_sheet_id,
nest_number,
focal,
species_code,
active,
stage,
adult_count,
chick_count,
chick_confidence,
comments
) VALUES (
%(data_sheet_id)s,
%(nest_number)s,
%(focal)s,
%(species_code)s,
%(active)s,
%(stage)s,
%(adult_count)s,
%(chick_count)s,
%(chick_confidence)s,
%(comments)s
)
""", {
'data_sheet_id': data_sheet_id,
'nest_number': number,
'focal': is_focal,
'species_code': species_code,
'active': active,
'stage': stage,
'adult_count': adult_count,
'chick_count': chick_count,
'chick_confidence': chick_confidence,
'comments': comments,
})
return jsonify(data)

@ -175,7 +175,7 @@ export const Datasheet = (props: Props) => {
colonyHumanDisturbance,
colonyHumanDisturbanceNotes,
colonyAdditionalObservations,
hepNestData,
hepNestData: hepNestData.filter(item => !!item.speciesCode),
}),
});
console.log(response);

@ -325,6 +325,23 @@ create table create_keys (
creation_date timestamp without time zone NOT NULL DEFAULT now()
);
create table hep_nest_data (
id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
data_sheet_id uuid NOT NULL,
nest_number int NOT NULL,
focal boolean NOT NULL,
species_code text NOT NULL,
active text NOT NULL,
stage int NOT NULL,
adult_count int NOT NULL,
chick_count int NOT NULL,
chick_confidence boolean NOT NULL,
comments text
);
ALTER TABLE ONLY hep_nest_data
ADD CONSTRAINT hep_nest_data_data_sheet_id_fkey FOREIGN KEY (data_sheet_id) REFERENCES data_sheet(id);
--
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: gyggowszznwhkm
--

Loading…
Cancel
Save