src/tesladata.py
def sleepy_to_sleep(mongo_db, influx_server="localhost", secondsback=7200):
    """
    sleepy_to_sleep calculates the difference in seconds between
    the state 'sleepy' and state 'asleep'. It looks 2 hours back
    in the 'custom_data' collection to find the state 'sleepy' and 
    for every 'sleepy' entry it finds, it will look in the 'vehicle'
    collection if the state change to 'asleep' within 1 hour after the
    'sleepy' state. 

    params:
      mongo_db: a mongodb database handle
      influx_server: the hostname of the influxdb server
    """
    custom_data = get_mongo_data(
        mongo_db,
        "custom_data",
        timestamp_start=generate_timestamp(min_secs=secondsback),
    )

    for doc in custom_data:
        ts_start = doc["timestamp"]
        ts_end = generate_timestamp(timestamp=ts_start, add_secs=3600)

        vehicle_data = get_mongo_data(
            mongo_db, "vehicle", timestamp_start=ts_start, timestamp_end=ts_end
        )

        for vdata in vehicle_data:
            if vdata["state"] == "asleep":
                ts_asleep = vdata["timestamp"]

                influx_write(
                    servername=influx_server,
                    measurement="custom_data",
                    entity="sleepy_to_sleep",
                    vin=vdata["vin"],
                    value=(ts_asleep - ts_start) / 1000,
                    ms=vdata["timestamp"],
                )

                break

    sleepy_to_sleep calculates the difference in seconds between
    the state 'sleepy' and state 'asleep'. It looks 2 hours back
    in the 'custom_data' collection to find the state 'sleepy' and 
    for every 'sleepy' entry it finds, it will look in the 'vehicle'
    collection if the state change to 'asleep' within 1 hour after the
    'sleepy' state. 

    params:
      mongo_db: a mongodb database handle
      influx_server: the hostname of the influxdb server
    
sleepy_to_sleep calculates the difference in seconds between
the state 'sleepy' and state 'asleep'.

a mongodb database handle
influx_server: the hostname of the influxdb server
sleepy_to_sleep calculates the difference in seconds between the state ' sleepy ' and state ' asleep ' . a mongodb database handle influx_server : the hostname of the influxdb server
def sleepy_to_sleep(mongo_db, influx_server="localhost", secondsback=7200):
    custom_data = get_mongo_data(
        mongo_db,
        "custom_data",
        timestamp_start=generate_timestamp(min_secs=secondsback),
    )
    for doc in custom_data:
        ts_start = doc["timestamp"]
        ts_end = generate_timestamp(timestamp=ts_start, add_secs=3600)
        vehicle_data = get_mongo_data(
            mongo_db, "vehicle", timestamp_start=ts_start, timestamp_end=ts_end
        )
        for vdata in vehicle_data:
            if vdata["state"] == "asleep":
                ts_asleep = vdata["timestamp"]
                influx_write(
                    servername=influx_server,
                    measurement="custom_data",
                    entity="sleepy_to_sleep",
                    vin=vdata["vin"],
                    value=(ts_asleep - ts_start) / 1000,
                    ms=vdata["timestamp"],
                )
                break
def sleepy_to_sleep ( mongo_db , influx_server = "localhost" , secondsback = 7200 ) : custom_data = get_mongo_data ( mongo_db , "custom_data" , timestamp_start = generate_timestamp ( min_secs = secondsback ) , ) for doc in custom_data : ts_start = doc [ "timestamp" ] ts_end = generate_timestamp ( timestamp = ts_start , add_secs = 3600 ) vehicle_data = get_mongo_data ( mongo_db , "vehicle" , timestamp_start = ts_start , timestamp_end = ts_end ) for vdata in vehicle_data : if vdata [ "state" ] == "asleep" : ts_asleep = vdata [ "timestamp" ] influx_write ( servername = influx_server , measurement = "custom_data" , entity = "sleepy_to_sleep" , vin = vdata [ "vin" ] , value = ( ts_asleep - ts_start ) / 1000 , ms = vdata [ "timestamp" ] , ) break
sleepy_to_sleep calculates the difference in seconds between
the state 'sleepy' and state 'asleep'.
sleepy_to_sleep calculates the difference in seconds between the state ' sleepy ' and state ' asleep ' .
"""
    sleepy_to_sleep calculates the difference in seconds between
    the state 'sleepy' and state 'asleep'. It looks 2 hours back
    in the 'custom_data' collection to find the state 'sleepy' and 
    for every 'sleepy' entry it finds, it will look in the 'vehicle'
    collection if the state change to 'asleep' within 1 hour after the
    'sleepy' state. 

    params:
      mongo_db: a mongodb database handle
      influx_server: the hostname of the influxdb server
    """
mongo_db
influx_server
secondsback