79327452

Date: 2025-01-03 19:20:51
Score: 1
Natty:
Report link

Finally I found a way to do what I needed, this is the function I used:

 def filter_measurement(stationid, measure, input_json):
        if input_json:
    
            data = jmespath.search("""
               sensors[].{
               value: data[].""" + measure + """,
               time: data[].ts,
               sensor_id: lsid
               }
               """, input_json)
    
            result_dic = []
    
            for i in data:
                if i["value"]:
                    num_values = len(i["value"])
                    for val in range(num_values):
                        date_val = datetime.fromtimestamp(i["time"][val])
                        result_dic.append({"station_id": stationid, "sensor_id": i["sensor_id"], "measurement": measure, "datetime": str(date_val), "Year": date_val.year, "Month": date_val.month, "Day": date_val.day, "Hour": date_val.hour, "Minute": date_val.minute, "value": i["value"][val]})
            return result_dic
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Claudia Sanchez