Update process_data.py
Browse files- process_data.py +90 -0
process_data.py
CHANGED
|
@@ -784,3 +784,93 @@ def parse_survey_stack_data(data):
|
|
| 784 |
print(processed_data)
|
| 785 |
|
| 786 |
return processed_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
print(processed_data)
|
| 785 |
|
| 786 |
return processed_data
|
| 787 |
+
|
| 788 |
+
def parse_survey_stack(data):
|
| 789 |
+
"""
|
| 790 |
+
Parse the incoming data from the survey stack survey
|
| 791 |
+
|
| 792 |
+
Args:
|
| 793 |
+
data: (json) JSON retrieved from surveystack API after retrieving survey info/details
|
| 794 |
+
|
| 795 |
+
Returns:
|
| 796 |
+
processed_data
|
| 797 |
+
processed_data["input_text"] = (str) the raw input text
|
| 798 |
+
"""
|
| 799 |
+
print("PROCESSING SURVEY STACK DATA")
|
| 800 |
+
processed_data = {}
|
| 801 |
+
|
| 802 |
+
print("JUST PRINTING OUT THE DATA FOR YA")
|
| 803 |
+
|
| 804 |
+
print(data)
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
processed_data["inputstyle"] = data[0]['data']['inputstyle']['value']
|
| 808 |
+
print("STEPWISE?: " + str(processed_data["inputstyle"]))
|
| 809 |
+
|
| 810 |
+
parameter_inputs = data[0]['data']['group_7']
|
| 811 |
+
processed_data["prompts"] = {}
|
| 812 |
+
|
| 813 |
+
if processed_data["inputstyle"][0] == "individual-pieces-input-text":
|
| 814 |
+
print("IN THE STEP")
|
| 815 |
+
farm_management_inputs = data[0]['data']['group_4']
|
| 816 |
+
print("FARM MANAGEMENT INPUTS" + str(farm_management_inputs))
|
| 817 |
+
|
| 818 |
+
processed_data["input_text_pieces"] = {}
|
| 819 |
+
processed_data["input_text_pieces"]["field_data_input"] = farm_management_inputs.get('field_data_input', {}).get('value', None)
|
| 820 |
+
processed_data["input_text_pieces"]["planting_data_input"] = farm_management_inputs.get('planting_data_input', {}).get('value', None)
|
| 821 |
+
processed_data["input_text_pieces"]["log_data_input"] = farm_management_inputs.get('log_data_input', {}).get('value', None)
|
| 822 |
+
processed_data["input_text_pieces"]["soil_data_input"] = farm_management_inputs.get('soil_data_input', {}).get('value', None)
|
| 823 |
+
processed_data["input_text_pieces"]["yield_data_input"] = farm_management_inputs.get('yield_data_input', {}).get('value', None)
|
| 824 |
+
processed_data["input_text"] = "EMPTY"
|
| 825 |
+
|
| 826 |
+
print("NEXT SCHEMA INPUTS")
|
| 827 |
+
interactions_inputs = data[0]['data']['group_5']
|
| 828 |
+
print("INTERACTIONS INPUTS" + str(interactions_inputs))
|
| 829 |
+
processed_data["input_text_pieces"]["interaction_data_input"] = interactions_inputs.get('interaction_data_input', {}).get('value', None)
|
| 830 |
+
processed_data["input_text_pieces"]["person_data_input"] = interactions_inputs.get('person_data_input', {}).get('value', None)
|
| 831 |
+
|
| 832 |
+
print("NEXT SCHEMA INPUTS 2")
|
| 833 |
+
trials_inputs = data[0]['data']['group_6']
|
| 834 |
+
print("TRIALS INPUTS" + str(trials_inputs))
|
| 835 |
+
processed_data["input_text_pieces"]["trial_data_input"] = trials_inputs.get('trial_data_input', {}).get('value', None)
|
| 836 |
+
processed_data["input_text_pieces"]["treatment_data_input"] = trials_inputs.get('treatment_data_input', {}).get('value', None)
|
| 837 |
+
|
| 838 |
+
print("NOW ONTO THE PROMPTS")
|
| 839 |
+
processed_data["prompts"]["first_schema_prompt_one"] = parameter_inputs.get('firstschemaprompt1', {}).get('value', None)
|
| 840 |
+
processed_data["prompts"]["first_schema_prompt_two"] = parameter_inputs.get('firstschemaprompt2', {}).get('value', None)
|
| 841 |
+
processed_data["prompts"]["first_schema_prompt_three"] = parameter_inputs.get('firstschemaprompt3', {}).get('value', None)
|
| 842 |
+
processed_data["prompts"]["first_schema_prompt_four"] = parameter_inputs.get('firstschemaprompt4', {}).get('value', None)
|
| 843 |
+
processed_data["prompts"]["first_schema_prompt_five"] = parameter_inputs.get('firstschemaprompt5', {}).get('value', None)
|
| 844 |
+
processed_data["prompts"]["second_schema_prompt_one"] = parameter_inputs.get('secondschemaprompt1', {}).get('value', None)
|
| 845 |
+
processed_data["prompts"]["second_schema_prompt_two"] = parameter_inputs.get('secondschemaprompt2', {}).get('value', None)
|
| 846 |
+
processed_data["prompts"]["third_schema_prompt_one"] = parameter_inputs.get('thirdschemaprompt1', {}).get('value', None)
|
| 847 |
+
processed_data["prompts"]["third_schema_prompt_two"] = parameter_inputs.get('thirdschemaprompt2', {}).get('value', None)
|
| 848 |
+
|
| 849 |
+
elif processed_data["stepwise_json_creation"][0] == "big-block-input-text":
|
| 850 |
+
print("IN THE SINGLE")
|
| 851 |
+
processed_data["input_text"] = data[0]['data']['onelonginputtext']['value']
|
| 852 |
+
print(processed_data["input_text"])
|
| 853 |
+
|
| 854 |
+
print("NOW ONTO THE PROMPTS")
|
| 855 |
+
processed_data["prompts"]["first_schema_prompt"] = parameter_inputs.get('firstschemaprompt', {}).get('value', None)
|
| 856 |
+
processed_data["prompts"]["second_schema_prompt"] = parameter_inputs.get('secondschemaprompt', {}).get('value', None)
|
| 857 |
+
processed_data["prompts"]["third_schema_prompt"] = parameter_inputs.get('thirdschemaprompt', {}).get('value', None)
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
# parameters
|
| 861 |
+
processed_data["parameters"] = {}
|
| 862 |
+
processed_data["parameters"]["model_version"] = data[0]['data']['modelversion']['value'][0] # this is one string
|
| 863 |
+
processed_data["parameters"]["pre_process"] = data[0]['data']['preprocessdata']['value'] # this is boolean
|
| 864 |
+
processed_data["parameters"]["prompt_style"] = data[0]['data']['promptstyle']['value'] # this is a list
|
| 865 |
+
|
| 866 |
+
if processed_data["parameters"]["pre_process"] == "yes":
|
| 867 |
+
processed_data["parameters"]["multiple_pre_prompts"] = data[0]['data']['multiplepreprompts']['value'] # this is a value in string words
|
| 868 |
+
processed_data["parameters"]["pre_prompt_style"] = data[0]['data']['prepromptstyle']['value'] # this is a list
|
| 869 |
+
processed_data["parameters"]["pre_prompt_first"] = data[0]['data']['preprocessingprompt1']['value']
|
| 870 |
+
processed_data["parameters"]["pre_prompt_second"] = data[0]['data']['preprocessingprompt2'].get('value', None)
|
| 871 |
+
processed_data["parameters"]["pre_prompt_third"] = data[0]['data']['preprocessingprompt3'].get('value', None)
|
| 872 |
+
|
| 873 |
+
print("RETURNING DATA")
|
| 874 |
+
print(processed_data)
|
| 875 |
+
|
| 876 |
+
return processed_data
|