import asyncio
from recordGenerators import alerts,currentObservations,hourlyForecast,dailyForecast, airQuality, airportDelays, achesAndPains, breathing, heatingAndCooling, mosquitoActivity, pollenForecast, tideForecast, wateringNeeds
from radar import radarCollector
from datetime import datetime


async def updateMosaicTask():
    mosaicUpdateIntervals = [i+1 for i in range(0, 60, 5)]

    while True:
        # Mosaic intervals are 5+1 minutes, so instead of waiting 40 seconds and running "Datetime.now()" twice, We run it once and wait for 60.
        if datetime.now().minute in mosaicUpdateIntervals:
            await radarCollector.collect("radarmosaic")
        await asyncio.sleep(1)

async def updateSatradTask():
    satradUpdateIntervals = [i+1 for i in range(0, 60, 10)]

    while True:
        #Satrad intervals are 10+1 minutes, so instead of waiting 40 seconds and running "Datetime.now()" twice, We run it once and wait for 60.
        if datetime.now().minute in satradUpdateIntervals:
            await radarCollector.collect("satrad")
        await asyncio.sleep(1)


async def alertsTask():
    while True:
        await alerts.makeRecord()
        await asyncio.sleep(60)

async def coTask():
    while True:
        await currentObservations.makeDataFile()
        await asyncio.sleep(5 * 60)

# These tasks should be updated every hour

async def hfTask():
    while True:
        await hourlyForecast.makeDataFile()
        await asyncio.sleep(60 * 60)

async def dfTask():
    while True:
        await dailyForecast.makeDataFile()
        await asyncio.sleep(60 * 60)

async def aqTask():
    while True:
        await airQuality.writeData()
        await asyncio.sleep(60 * 60)

async def aptTask():
    while True:
        await airportDelays.writeData()
        await asyncio.sleep(60 * 60)

async def apTask():
    while True:
        await achesAndPains.makeRecord()
        await asyncio.sleep(60 * 60)

async def brTask():
    while True:
        await breathing.makeDataFile()
        await asyncio.sleep(60 * 60)

async def hcTask():
    while True:
        await heatingAndCooling.makeRecord()
        await asyncio.sleep(60 * 60)

async def maTask():
    while True:
        await mosquitoActivity.makeRecord()
        await asyncio.sleep(60 * 60)

async def pTask():
    while True:
        await pollenForecast.makeDataFile()
        await asyncio.sleep(60 * 60)

async def tTask():
    while True:
        await tideForecast.makeRecord()
        await asyncio.sleep(60 * 60)

async def wnTask():
    while True:
        await wateringNeeds.makeRecord()
        await asyncio.sleep(60 * 60)
