#Python's program to calulate the Wind Chill Index (WCI)
#The wind chill index is only considered valid for temperatures less than or
#equal to 10 degrees Celsius and wind speeds exceeding 4.8 kilometers per hour.

import datetime
from datetime import  datetime
import time
import os

now = datetime.now()


#Define the constants
WINDCHILL_OFFSET    = float(13.12)
WINDCHILL_FACTOR1   = float(0.6215)
WINDCHILL_FACTOR2   = float(-11.37)
WINDCHILL_FACTOR3   = float(0.3965)
WINDCHILL_EXP       = float(0.16)

# 1 mph to kph = 1.60934 kph


f = open("windspeed.text", "r")
windspeed = (f.read())
f.close()

speed = float(windspeed)

# convert speed in mph to kph
#speed = (speed*1.69034)

f = open("temperature.txt", "r")
temp = (f.read())
f.close()

temp=float(temp)



time.sleep(6)

if (temp>10) or (speed < 3.0):
    print("windchill not applicable if air temperature is above 10 deg C or windspeed is below 3 mph")

    print("windspeed " , windspeed)
    print("temp  " , temp)
    f=open("windchill.txt" , "w")
    f.write("windchill not applicable")

    now = datetime.now()
    current_time  = now.strftime("%H:%M")
    print(current_time)

    f = open("windchilltime.txt" , "w")
    f.write(current_time)
    f.close()

else:
	print("speed   " , speed)
	print("temp: " , temp)
#Calculate the WCI
	wci     = WINDCHILL_OFFSET + (WINDCHILL_FACTOR1 * temp) + (WINDCHILL_FACTOR2 * speed ** WINDCHILL_EXP) + (WINDCHILL_FACTOR3 * temp * speed ** WINDCHILL_EXP)

	print("wind chill ",  wci)


 #wci = (str(wci))


	wci = (round(wci , 1))
	wci = (str(wci))

	f = open("windchill.txt" , "w")
	f.write(wci)
	f.close()


now = datetime.now()
current_time  = now.strftime("%H:%M")


f = open("windchilltime.txt" , "w")
f.write(current_time)
f.close()
