update
This commit is contained in:
parent
2ace390c35
commit
25b30c420a
203
Server.py
203
Server.py
@ -1,203 +0,0 @@
|
||||
import socket,threading,os,time,math,json,sys,urllib,requests,ctypes,inspect,signal
|
||||
sys.path.append('libraries\\')
|
||||
from Astronomy import *
|
||||
#-------------------------------------#
|
||||
#Define Area
|
||||
class APICore(object):
|
||||
HTTPHead={
|
||||
'200':'HTTP/1.1 200 OK\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n',
|
||||
'400':'HTTP/1.1 400 BAD REQUEST\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n',
|
||||
'404':'HTTP/1.1 404 NOT FOUND\r\nServer: SparkEG/Alpha1.0\r\nContent-Type: application/json; charset=utf-8\r\n\r\n'
|
||||
}
|
||||
def __init__(self):
|
||||
self.__Log=[]
|
||||
def Log(self,IP,Port,Type,Text):
|
||||
Time=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
|
||||
self.__Log.append((Time,IP,Port,Type,Text))
|
||||
print("["+Type+"]["+Time+"]["+IP+"]["+str(Port)+"]"+str(Text))
|
||||
def MakeDir(self,Path):
|
||||
if(not os.path.isdir(Path)):
|
||||
os.makedirs(Path)
|
||||
def LogOutput(self):
|
||||
self.MakeDir("logs")
|
||||
with open(time.strftime("logs\\%Y-%m-%d-%H-%M-%S.txt",time.localtime()),"w+") as FileObject:
|
||||
FileObject.write("GHINK API Logs "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n")
|
||||
for text in self.__Log:
|
||||
FileObject.write("["+str(text[0])+"]["+str(text[1])+"]["+str(text[2])+"]["+str(text[3])+"]"+str(text[4])+"\n")
|
||||
self.__Log=[]
|
||||
def AutoLogOutput(self):
|
||||
while(True):
|
||||
time.sleep(3600)
|
||||
self.LogOutput()
|
||||
def IsJson(self,text):
|
||||
try:
|
||||
json.loads(text)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
def Error400(self,sock,addr):
|
||||
sock.send(self.HTTPHead['400'].encode("utf-8"))
|
||||
Result=json.dumps({"info":"bad request","code":400})
|
||||
self.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf-8"))
|
||||
def SunAzEl(self,sock,addr):
|
||||
Result=json.dumps(Astronomy().calcSunAzEl())
|
||||
self.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf-8"))
|
||||
#-------------------------------------#
|
||||
API=APICore()
|
||||
#-------------------------------------#
|
||||
RequestRecord={}
|
||||
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
server.bind(("0.0.0.0",8000))
|
||||
server.listen()
|
||||
def listen():
|
||||
while True:
|
||||
sock,addr=server.accept()
|
||||
client_thread=threading.Thread(target=socket,args=(sock,addr))
|
||||
client_thread.start()
|
||||
def socket(sock,addr):
|
||||
while True:
|
||||
try:
|
||||
data = sock.recv(1024)
|
||||
#print(data.decode("utf-8"))
|
||||
if("HTTP/" in data.decode("utf-8")):
|
||||
API.Log(addr[0],addr[1],"RECV","Received a HTTP request.")
|
||||
#HTTP Request.
|
||||
Type="HTTP"
|
||||
try:
|
||||
Heada=data.decode("utf-8").split("\r\n")[0].split(" ")[1].split("/")
|
||||
del Heada[0]
|
||||
except:
|
||||
API.Error400(sock,addr)
|
||||
break
|
||||
try:
|
||||
Headb=data.decode("utf-8").split("\r\n\r\n")[1]
|
||||
except:
|
||||
Headb=""
|
||||
HTTPRequestHead=(Heada,Headb)
|
||||
for i in range(0,len(HTTPRequestHead[0])):
|
||||
HTTPRequestHead[0][i]=urllib.parse.unquote(HTTPRequestHead[0][i])
|
||||
API.Log(addr[0],addr[1],"RECV",HTTPRequestHead)
|
||||
if(" / " in data.decode("utf-8")):
|
||||
#Help Command
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
Result=json.dumps({"wikis":"https://gitee.com/ghink/api/wikis"})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf8"))
|
||||
break
|
||||
elif(" /SunAzEl" in data.decode("utf-8")):
|
||||
if("GET " in data.decode("utf-8")):
|
||||
#GET Request
|
||||
try:
|
||||
#Exist Parameter
|
||||
HTTPRequestHead[0][1]
|
||||
if(API.IsJson(HTTPRequestHead[0][1])):
|
||||
#Is Json,Return Result
|
||||
try:
|
||||
Para=json.loads(HTTPRequestHead[0][1])
|
||||
Result=json.dumps(Astronomy().calcSunAzEl(Para['Stamp'],Para['Lon'],Para['Lat'],Para['TimeZone'],Para['ZeroAzimuth']))
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf-8"))
|
||||
except:
|
||||
API.Error400(sock,addr)
|
||||
else:
|
||||
#Not Json,Return Bad Request
|
||||
API.Error400(sock,addr)
|
||||
except:
|
||||
#No Parameter
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
API.SunAzEl(sock,addr)
|
||||
elif("POST " in data.decode("utf-8")):
|
||||
#POST Request
|
||||
try:
|
||||
#Exist GET Parameter,Return Bad Request
|
||||
HTTPRequestHead[0][1]
|
||||
API.Error400(sock,addr)
|
||||
except:
|
||||
#No GET Parameter,Continue
|
||||
if(API.IsJson(HTTPRequestHead[1])):
|
||||
#If POST Parameter is Json
|
||||
try:
|
||||
Para=json.loads(HTTPRequestHead[1])
|
||||
Result=json.dumps(Astronomy().calcSunAzEl(Para['Stamp'],Para['Lon'],Para['Lat'],Para['TimeZone'],Para['ZeroAzimuth']))
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf-8"))
|
||||
except:
|
||||
API.Error400(sock,addr)
|
||||
elif(HTTPRequestHead[1]==""):
|
||||
#If No POST Parameter
|
||||
sock.send(API.HTTPHead['200'].encode("utf-8"))
|
||||
API.SunAzEl(sock,addr)
|
||||
else:
|
||||
#Wrong POST Parameter,Return Bad Request
|
||||
API.Error400(sock,addr)
|
||||
break
|
||||
else:
|
||||
#No Such Command
|
||||
sock.send(API.HTTPHead['404'].encode("utf8"))
|
||||
Result=json.dumps({"info":"not found","code":404})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(Result.encode("utf-8"))
|
||||
break
|
||||
else:
|
||||
API.Log(addr[0],addr[1],"RECV","Received a TCP request.")
|
||||
#TCP Request.
|
||||
Type="TCP"
|
||||
if(data.decode("utf-8")=="Help" or data.decode("utf-8")=="HELP" or data.decode("utf-8")=="help" or data.decode("utf-8")=="WIKI" or data.decode("utf-8")=="wiki" or data.decode("utf-8")=="wikis" or data.decode("utf-8")=="WIKIS" or data.decode("utf-8")=="?"):
|
||||
#Help Command
|
||||
Result=json.dumps({"wikis":"https://gitee.com/ghink/api/wikis"})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf8"))
|
||||
elif("SunAzEl" in data.decode("utf-8")):
|
||||
if(API.IsJson(data.decode("utf-8"))):
|
||||
#Is Json
|
||||
try:
|
||||
#Check whether is right json
|
||||
Para=json.loads(data.decode("utf-8"))['Parameter']
|
||||
Result=json.dumps(Astronomy().calcSunAzEl(Para['Stamp'],Para['Lon'],Para['Lat'],Para['TimeZone'],Para['ZeroAzimuth']))
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(str(Result).encode("utf-8"))
|
||||
except:
|
||||
#Not right json
|
||||
Result=json.dumps({"info":"bad request","code":400})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(Result.encode("utf-8"))
|
||||
elif(data.decode("utf-8")=="SunAzEl"):
|
||||
#Not Json
|
||||
API.SunAzEl(sock,addr)
|
||||
else:
|
||||
#Wrong Command
|
||||
Result=json.dumps({"info":"bad request","code":400})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(Result.encode("utf-8"))
|
||||
else:
|
||||
#No Such Command
|
||||
Result=json.dumps({"info":"not found","code":404})
|
||||
API.Log(addr[0],addr[1],"SEND",Result)
|
||||
sock.send(Result.encode("utf-8"))
|
||||
except (ConnectionResetError,ConnectionAbortedError):
|
||||
API.Log(addr[0],addr[1],"STATUS","Lost connection.")
|
||||
break
|
||||
except UnicodeDecodeError:
|
||||
API.Log(addr[0],addr[1],"STATUS","Wrong code mode,must be utf-8.")
|
||||
API.Log(addr[0],addr[1],"STATUS","Lost connection.")
|
||||
break
|
||||
if Type=="HTTP":
|
||||
sock.close()
|
||||
def main():
|
||||
LogOutput=API.AutoLogOutput
|
||||
log_thread=threading.Thread(target=LogOutput,args=())
|
||||
log_thread.start()
|
||||
listen_thread=threading.Thread(target=listen,args=())
|
||||
listen_thread.start()
|
||||
while(True):
|
||||
ManagerCommand=input("")
|
||||
if(ManagerCommand=="exit"):
|
||||
API.LogOutput()
|
||||
os.kill(os.getpid(),signal.SIGTERM)
|
||||
elif(ManagerCommand=="savelog"):
|
||||
API.LogOutput()
|
||||
main()
|
@ -1,161 +0,0 @@
|
||||
import os,time,math
|
||||
#-------------------------------------#
|
||||
class Astronomy(object):
|
||||
def calcSunDeclination(self,Stamp=None,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0
|
||||
def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525
|
||||
L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone)
|
||||
while (TrueSolarTime > 1440):
|
||||
TrueSolarTime -= 1440
|
||||
HourAngle = TrueSolarTime / 4 - 180.0
|
||||
if (HourAngle < -180):
|
||||
HourAngle += 360.0
|
||||
return HourAngle
|
||||
def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0
|
||||
csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone)))
|
||||
if(csz > 1):
|
||||
csz = 1
|
||||
elif(csz < -1):
|
||||
csz = -1
|
||||
if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001):
|
||||
azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))
|
||||
if(abs(azRad) > 1.0):
|
||||
if(azRad < 0):
|
||||
azRad = -1.0
|
||||
else:
|
||||
azRad = 1.0
|
||||
azimuth = 180.0 - math.degrees(math.acos(azRad))
|
||||
if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0):
|
||||
azimuth = -azimuth
|
||||
else:
|
||||
if(Lat > 0.0):
|
||||
azimuth = 180.0
|
||||
else:
|
||||
azimuth = 0.0
|
||||
if(azimuth < 0.0):
|
||||
azimuth += 360.0
|
||||
exoatmElevation = (90.0 - math.degrees(math.acos(csz)))
|
||||
if (exoatmElevation > 85.0):
|
||||
refractionCorrection = 0.0
|
||||
else:
|
||||
te = math.tan (math.radians(exoatmElevation))
|
||||
if (exoatmElevation > 5.0):
|
||||
refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te)
|
||||
elif (exoatmElevation > -0.575):
|
||||
refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) )
|
||||
else:
|
||||
refractionCorrection = -20.774 / te
|
||||
refractionCorrection = refractionCorrection / 3600.0
|
||||
solarZen = math.degrees(math.acos(csz)) - refractionCorrection
|
||||
return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0}
|
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
$command="python api_core.py";
|
||||
if($_GET['stamp']!=""){
|
||||
$command=$command." --stamp ".strval($_GET['stamp'])." ";
|
||||
}
|
||||
if($_GET['lon']!=""){
|
||||
$command=$command." --lon ".$_GET['lon']." ";
|
||||
}
|
||||
if($_GET['zone']!=""){
|
||||
$command=$command." --zone ".$_GET['zone']." ";
|
||||
}
|
||||
@os.system($command);
|
||||
?>
|
@ -1,168 +0,0 @@
|
||||
import os,time,math,argparse,json
|
||||
#-------------------------------------#
|
||||
class Calendar(object):
|
||||
def calcSunDeclination(self,Stamp=None,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0
|
||||
def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525
|
||||
L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone)
|
||||
while (TrueSolarTime > 1440):
|
||||
TrueSolarTime -= 1440
|
||||
HourAngle = TrueSolarTime / 4 - 180.0
|
||||
if (HourAngle < -180):
|
||||
HourAngle += 360.0
|
||||
return HourAngle
|
||||
def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0
|
||||
csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone)))
|
||||
if(csz > 1):
|
||||
csz = 1
|
||||
elif(csz < -1):
|
||||
csz = -1
|
||||
if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001):
|
||||
azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))
|
||||
if(abs(azRad) > 1.0):
|
||||
if(azRad < 0):
|
||||
azRad = -1.0
|
||||
else:
|
||||
azRad = 1.0
|
||||
azimuth = 180.0 - math.degrees(math.acos(azRad))
|
||||
if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0):
|
||||
azimuth = -azimuth
|
||||
else:
|
||||
if(Lat > 0.0):
|
||||
azimuth = 180.0
|
||||
else:
|
||||
azimuth = 0.0
|
||||
if(azimuth < 0.0):
|
||||
azimuth += 360.0
|
||||
exoatmElevation = (90.0 - math.degrees(math.acos(csz)))
|
||||
if (exoatmElevation > 85.0):
|
||||
refractionCorrection = 0.0
|
||||
else:
|
||||
te = math.tan (math.radians(exoatmElevation))
|
||||
if (exoatmElevation > 5.0):
|
||||
refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te)
|
||||
elif (exoatmElevation > -0.575):
|
||||
refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) )
|
||||
else:
|
||||
refractionCorrection = -20.774 / te
|
||||
refractionCorrection = refractionCorrection / 3600.0
|
||||
solarZen = math.degrees(math.acos(csz)) - refractionCorrection
|
||||
return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0}
|
||||
c=Calendar()
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--stamp",default=time.time())
|
||||
parser.add_argument("--lon",default=120)
|
||||
parser.add_argument("--zone",default=8)
|
||||
parser=parser.parse_args()
|
||||
print(json.dumps(c.calcHourAngle(int(parser.stamp),int(parser.lon),int(parser.zone))))
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
$command="python api_core.py";
|
||||
if($_GET['stamp']!=""){
|
||||
$command=$command." --stamp ".strval($_GET['stamp'])." ";
|
||||
}
|
||||
if($_GET['lon']!=""){
|
||||
$command=$command." --lon ".$_GET['lon']." ";
|
||||
}
|
||||
if($_GET['lat']!=""){
|
||||
$command=$command." --lat ".$_GET['lat']." ";
|
||||
}
|
||||
if($_GET['zone']!=""){
|
||||
$command=$command." --zone ".$_GET['zone']." ";
|
||||
}
|
||||
if($_GET['zero']!=""){
|
||||
$command=$command." --zero ".$_GET['zero']." ";
|
||||
}
|
||||
@os.system($command);
|
||||
?>
|
@ -1,170 +0,0 @@
|
||||
import os,time,math,argparse,json
|
||||
#-------------------------------------#
|
||||
class Calendar(object):
|
||||
def calcSunDeclination(self,Stamp=None,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0
|
||||
def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525
|
||||
L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone)
|
||||
while (TrueSolarTime > 1440):
|
||||
TrueSolarTime -= 1440
|
||||
HourAngle = TrueSolarTime / 4 - 180.0
|
||||
if (HourAngle < -180):
|
||||
HourAngle += 360.0
|
||||
return HourAngle
|
||||
def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0
|
||||
csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone)))
|
||||
if(csz > 1):
|
||||
csz = 1
|
||||
elif(csz < -1):
|
||||
csz = -1
|
||||
if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001):
|
||||
azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))
|
||||
if(abs(azRad) > 1.0):
|
||||
if(azRad < 0):
|
||||
azRad = -1.0
|
||||
else:
|
||||
azRad = 1.0
|
||||
azimuth = 180.0 - math.degrees(math.acos(azRad))
|
||||
if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0):
|
||||
azimuth = -azimuth
|
||||
else:
|
||||
if(Lat > 0.0):
|
||||
azimuth = 180.0
|
||||
else:
|
||||
azimuth = 0.0
|
||||
if(azimuth < 0.0):
|
||||
azimuth += 360.0
|
||||
exoatmElevation = (90.0 - math.degrees(math.acos(csz)))
|
||||
if (exoatmElevation > 85.0):
|
||||
refractionCorrection = 0.0
|
||||
else:
|
||||
te = math.tan (math.radians(exoatmElevation))
|
||||
if (exoatmElevation > 5.0):
|
||||
refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te)
|
||||
elif (exoatmElevation > -0.575):
|
||||
refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) )
|
||||
else:
|
||||
refractionCorrection = -20.774 / te
|
||||
refractionCorrection = refractionCorrection / 3600.0
|
||||
solarZen = math.degrees(math.acos(csz)) - refractionCorrection
|
||||
return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0}
|
||||
c=Calendar()
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--stamp",default=time.time())
|
||||
parser.add_argument("--lon",default=120)
|
||||
parser.add_argument("--lat",default=30)
|
||||
parser.add_argument("--zone",default=8)
|
||||
parser.add_argument("--zero",default="North")
|
||||
parser=parser.parse_args()
|
||||
print(json.dumps(c.calcSunAzEl(int(parser.stamp),int(parser.lon),int(parser.lat),int(parser.zone),parser.zero)))
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
$command="python api_core.py";
|
||||
if($_GET['stamp']!=""){
|
||||
$command=$command." --stamp ".strval($_GET['stamp'])." ";
|
||||
}
|
||||
if($_GET['zone']!=""){
|
||||
$command=$command." --zone ".$_GET['zone']." ";
|
||||
}
|
||||
@os.system($command);
|
||||
?>
|
@ -1,168 +0,0 @@
|
||||
import os,time,math,argparse,json
|
||||
#-------------------------------------#
|
||||
class Calendar(object):
|
||||
def calcSunDeclination(self,Stamp=None,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
L0 = 280.46646 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (36000.76983 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
return (math.degrees(math.asin(math.sin(math.radians(23 + (26 + ((21.448 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (46.8150 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.00059 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))) * math.sin(math.radians(L0 + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)))) * (1.914602 - ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (0.004817 + 0.000014 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 2) * (0.019993 - 0.000101 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525)) + math.sin(math.radians(357.52911 + ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525) * (359995029 - 0.0001537 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))) * 3) * 0.000289 - 0.00569 - 0.00478 * math.sin(math.radians(1254 - 1934.136 * ((math.floor(365.25 * (Year + 4716)) + math.floor(30.6001 * (Month + 1)) + Day + 2 - math.floor(Year / 100) + math.floor(math.floor(Year / 100) / 4) - 1524.5 + (Hour * 60 + Minute + Second/60.0) / 1440.0 - TimeZone / 24 - 2451545) / 36525))))))) * 100 + 0.5) / 100.0
|
||||
def calcHourAngle(self,Stamp=None,Lon=120,TimeZone=8):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
TimeJulianCent = (math.floor(365.25*(Year + 4716)) + math.floor(30.6001*(Month+1)) + Day + 2 - math.floor(Year/100) + math.floor(math.floor(Year/100)/4) - 1524.5 + Hour * 60 + Minute + Second/60.0/1440.0 - TimeZone/24 - 2451545)/36525
|
||||
L0 = 280.46646 + TimeJulianCent * (36000.76983 + TimeJulianCent *(0.0003032))
|
||||
while(L0 > 360.0):
|
||||
L0 -= 360.0
|
||||
while(L0 < 0.0):
|
||||
L0 += 360.0
|
||||
TrueSolarTime = (Hour * 60 + Minute + Second / 60) + ((4 * math.degrees((math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(2 * math.radians(L0)) - 2 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) + 4 * (0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent)))) / 2) ** 2) * math.sin(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent))) * math.cos(2 * math.radians(L0)) - 0.5 * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * (math.tan(math.radians((23 + (26 + ((21.448 - TimeJulianCent * (46.8150 + TimeJulianCent * (0.00059 - TimeJulianCent * (0.001813)))) / 60.0)) / 60.0 + 0.00256 * math.cos(math.radians(1254 - 1934.136 * TimeJulianCent))))/2) ** 2) * math.sin(4 * math.radians(L0)) - 1.25 * ((0.016708634 - TimeJulianCent * (0.000042037 + 0.0000001267 * TimeJulianCent)) ** 2) * math.sin(2 * math.radians(math.radians(357.52911 + TimeJulianCent * (359995029 - 0.0001537 * TimeJulianCent)))))) + 4 * Lon - 60.0 * TimeZone)
|
||||
while (TrueSolarTime > 1440):
|
||||
TrueSolarTime -= 1440
|
||||
HourAngle = TrueSolarTime / 4 - 180.0
|
||||
if (HourAngle < -180):
|
||||
HourAngle += 360.0
|
||||
return HourAngle
|
||||
def calcSunAzEl(self,Stamp=None,Lon=120,Lat=30,TimeZone=8,ZeroAzimuth="North"):
|
||||
MonthList = [
|
||||
{"name": 'January', "numdays": 31},
|
||||
{"name": 'February', "numdays": 28},
|
||||
{"name": 'March', "numdays": 31},
|
||||
{"name": 'April', "numdays": 30},
|
||||
{"name": 'May', "numdays": 31},
|
||||
{"name": 'June', "numdays": 30},
|
||||
{"name": 'July', "numdays": 31},
|
||||
{"name": 'August', "numdays": 31},
|
||||
{"name": 'September', "numdays": 30},
|
||||
{"name": 'October', "numdays": 31},
|
||||
{"name": 'November', "numdays": 30},
|
||||
{"name": 'December', "numdays": 31},
|
||||
]
|
||||
if(Stamp==None):
|
||||
TimeStamp = time.time()
|
||||
else:
|
||||
TimeStamp = Stamp
|
||||
Year=int(time.strftime("%Y",time.localtime(TimeStamp)))
|
||||
Month=int(time.strftime("%m",time.localtime(TimeStamp)))
|
||||
Day=int(time.strftime("%d",time.localtime(TimeStamp)))
|
||||
Hour=int(time.strftime("%H",time.localtime(TimeStamp)))
|
||||
Minute=int(time.strftime("%M",time.localtime(TimeStamp)))
|
||||
Second=int(time.strftime("%S",time.localtime(TimeStamp)))
|
||||
if(((Year % 4 == 0 and Year % 100 != 0) or Year % 400 == 0) and (Month == 2)):
|
||||
if(Day > 29):
|
||||
Day=29
|
||||
else:
|
||||
if(Day > MonthList[Month-1]['numdays']):
|
||||
Day = MonthList[Month-1]['numdays']
|
||||
if(Month <= 2):
|
||||
Year -= 1
|
||||
Month += 12
|
||||
ZeroAzimuth=180 if(ZeroAzimuth=="South") else 0
|
||||
csz = math.sin(math.radians(Lat)) * math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone))) + math.cos(math.radians(Lat)) * math.cos(math.radians(self.calcSunDeclination(Stamp,TimeZone))) * math.cos(math.radians(self.calcHourAngle(Stamp,Lon,TimeZone)))
|
||||
if(csz > 1):
|
||||
csz = 1
|
||||
elif(csz < -1):
|
||||
csz = -1
|
||||
if(abs((math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))) > 0.001):
|
||||
azRad = ((math.sin(math.radians(Lat)) * math.cos(math.radians(math.degrees(math.acos(csz))))) - math.sin(math.radians(self.calcSunDeclination(Stamp,TimeZone)))) / (math.cos(math.radians(Lat)) * math.sin(math.radians(math.degrees(math.acos(csz)))))
|
||||
if(abs(azRad) > 1.0):
|
||||
if(azRad < 0):
|
||||
azRad = -1.0
|
||||
else:
|
||||
azRad = 1.0
|
||||
azimuth = 180.0 - math.degrees(math.acos(azRad))
|
||||
if(self.calcHourAngle(Stamp,Lon,TimeZone) > 0.0):
|
||||
azimuth = -azimuth
|
||||
else:
|
||||
if(Lat > 0.0):
|
||||
azimuth = 180.0
|
||||
else:
|
||||
azimuth = 0.0
|
||||
if(azimuth < 0.0):
|
||||
azimuth += 360.0
|
||||
exoatmElevation = (90.0 - math.degrees(math.acos(csz)))
|
||||
if (exoatmElevation > 85.0):
|
||||
refractionCorrection = 0.0
|
||||
else:
|
||||
te = math.tan (math.radians(exoatmElevation))
|
||||
if (exoatmElevation > 5.0):
|
||||
refractionCorrection = 58.1 / te - 0.07 / (te*te*te) + 0.000086 / (te*te*te*te*te)
|
||||
elif (exoatmElevation > -0.575):
|
||||
refractionCorrection = 1735.0 + exoatmElevation * (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711) ) )
|
||||
else:
|
||||
refractionCorrection = -20.774 / te
|
||||
refractionCorrection = refractionCorrection / 3600.0
|
||||
solarZen = math.degrees(math.acos(csz)) - refractionCorrection
|
||||
return {"az":((azimuth*100 +0.5) - (ZeroAzimuth*100))/100.0,"el":((90.0-solarZen)*100+0.5)/100.0}
|
||||
c=Calendar()
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--stamp",default=time.time())
|
||||
parser.add_argument("--lon",default=120)
|
||||
parser.add_argument("--zone",default=8)
|
||||
parser=parser.parse_args()
|
||||
print(json.dumps(c.calcSunDeclination(int(parser.stamp),int(parser.zone))))
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
header("Content-type:application/json");
|
||||
$db=mysqli_connect("localhost","ghinkapi","ghink2014","ghinkapi");
|
||||
mysqli_query($db,"set names utf8");
|
||||
if($_GET['type']==""){
|
||||
$result_md5=mysqli_fetch_array(mysqli_query($db,"SELECT * FROM `crypt_md5` WHERE `encrypted`='".$_GET['text']."'"));
|
||||
$result_sha1=mysqli_fetch_array(mysqli_query($db,"SELECT * FROM `crypt_sha1` WHERE `encrypted`='".$_GET['text']."'"));
|
||||
if(empty($result_md5) and !empty($result_sha1)){
|
||||
echo $result_sha1['unencrypted'];
|
||||
}elseif(!empty($result_md5) and empty($result_sha1)){
|
||||
echo $result_md5['unencrypted'];
|
||||
}else{
|
||||
echo '["md5":"'.$result_md5['unencrypted'].'","sha1":"'.$result_sha1['unencrypted'].'"]';
|
||||
}
|
||||
}elseif($_GET['type']=="md5"){
|
||||
$result_md5=mysqli_fetch_array(mysqli_query($db,"SELECT * FROM `crypt_md5` WHERE `encrypted`='".$_GET['text']."'"));
|
||||
if(empty($result_md5)){
|
||||
echo '{"error":"10003"}';
|
||||
}else{
|
||||
echo $result_md5['unencrypted'];
|
||||
}
|
||||
}elseif($_GET['type']=="sha1"){
|
||||
$result_sha1=mysqli_fetch_array(mysqli_query($db,"SELECT * FROM `crypt_sha1` WHERE `encrypted`='".$_GET['text']."'"));
|
||||
if(empty($result_sha1)){
|
||||
echo '{"error":"10003"}';
|
||||
}else{
|
||||
echo $result_sha1['unencrypted'];
|
||||
}
|
||||
}else{
|
||||
echo '{"error":"10004"}';
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
header("Content-type:text/html;charset=utf-8");
|
||||
$db=mysqli_connect("localhost","ghinkapi","ghink2014","ghinkapi");
|
||||
mysqli_query($db,"set names utf8");
|
||||
if($_GET['type']==""){
|
||||
if($_POST['text']!=""){
|
||||
if($_GET['text']!=""){
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10000"}';
|
||||
$encrypt_result=false;
|
||||
}else{
|
||||
$encrypt_result=md5($_POST['text']);
|
||||
$unencrypted=$_POST['text'];
|
||||
}
|
||||
}else{
|
||||
if($_GET['text']!=""){
|
||||
$encrypt_result=md5($_GET['text']);
|
||||
$unencrypted=$_GET['text'];
|
||||
}else{
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10001"}';
|
||||
$encrypt_result=false;
|
||||
}
|
||||
}
|
||||
if($encrypt_result!=false){;
|
||||
echo $encrypt_result;
|
||||
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_md5` WHERE `unencrypted`='".$unencrypted."'");
|
||||
if(empty(mysqli_fetch_array($result))){
|
||||
mysqli_query($db,"INSERT INTO `crypt_md5` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
|
||||
}
|
||||
}
|
||||
}elseif($_GET['type']=="md5"){
|
||||
if($_POST['text']!=""){
|
||||
if($_GET['text']!=""){
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10000"}';
|
||||
$encrypt_result=false;
|
||||
}else{
|
||||
$encrypt_result=md5($_POST['text']);
|
||||
$unencrypted=$_POST['text'];
|
||||
}
|
||||
}else{
|
||||
if($_GET['text']!=""){
|
||||
$encrypt_result=md5($_GET['text']);
|
||||
$unencrypted=$_GET['text'];
|
||||
}else{
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10001"}';
|
||||
$encrypt_result=false;
|
||||
}
|
||||
}
|
||||
if($encrypt_result!=false){
|
||||
echo $encrypt_result;
|
||||
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_md5` WHERE `unencrypted`='".$unencrypted."'");
|
||||
if(empty(mysqli_fetch_array($result))){
|
||||
mysqli_query($db,"INSERT INTO `crypt_md5` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
|
||||
}
|
||||
}
|
||||
}elseif($_GET['type']=="sha1"){
|
||||
if($_POST['text']!=""){
|
||||
if($_GET['text']!=""){
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10000"}';
|
||||
$encrypt_result=false;
|
||||
}else{
|
||||
$encrypt_result=sha1($_POST['text']);
|
||||
$unencrypted=$_POST['text'];
|
||||
}
|
||||
}else{
|
||||
if($_GET['text']!=""){
|
||||
$encrypt_result=sha1($_GET['text']);
|
||||
$unencrypted=$_GET['text'];
|
||||
}else{
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10001"}';
|
||||
$encrypt_result=false;
|
||||
}
|
||||
}
|
||||
if($encrypt_result!=false){
|
||||
echo $encrypt_result;
|
||||
$result=mysqli_query($db,"SELECT `unencrypted` FROM `crypt_sha1` WHERE `unencrypted`='".$unencrypted."'");
|
||||
if(empty(mysqli_fetch_array($result))){
|
||||
mysqli_query($db,"INSERT INTO `crypt_sha1` (`unencrypted`, `encrypted`) VALUES ('".$unencrypted."', '".$encrypt_result."')");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
header("Content-type:application/json");
|
||||
echo '{"error":"10004"}';
|
||||
}
|
||||
mysqli_close($db);
|
@ -1,232 +0,0 @@
|
||||
<?php
|
||||
//Copyright GHINK Network Studio.
|
||||
//LGPLv3.0
|
||||
//---------------------------------------------------------------------//
|
||||
error_reporting(0);//抑制报错
|
||||
$stream_opts = [//防止https证书错误
|
||||
"ssl" => [
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false,
|
||||
]
|
||||
];
|
||||
//读取API JSON并转为数组
|
||||
$teamjson=file_get_contents("http://api.ghink.net/fah/json/?team=".$_GET['team'],false, stream_context_create($stream_opts));
|
||||
$donorjson=file_get_contents("http://api.ghink.net/fah/json/?donor=".$_GET['donor'],false, stream_context_create($stream_opts));
|
||||
$team=json_decode($teamjson, true);
|
||||
$donor=json_decode($donorjson, true);
|
||||
//---------------------------------------------------------------------//
|
||||
foreach ($team as $key => $value) { //遍历数组,读取数据
|
||||
if($key='name'){
|
||||
$teamname=$team['name'];
|
||||
}
|
||||
}
|
||||
foreach ($team as $key => $value) {
|
||||
if($key='team'){
|
||||
$teamid=$team['team'];
|
||||
}
|
||||
}
|
||||
foreach ($team as $key => $value) {
|
||||
if($key='rank'){
|
||||
$teamrank=$team['rank'];
|
||||
}
|
||||
}
|
||||
foreach ($team as $key => $value) {
|
||||
if($key='wus'){
|
||||
$teamwus=$team['wus'];
|
||||
}
|
||||
}
|
||||
foreach ($team as $key => $value) {
|
||||
if($key='credit'){
|
||||
$teamscores=$team['credit'];
|
||||
}
|
||||
}
|
||||
foreach ($donor as $key => $value) {
|
||||
if($key='name'){
|
||||
$name=$donor['name'];
|
||||
}
|
||||
}
|
||||
foreach ($donor as $key => $value) {
|
||||
if($key='rank'){
|
||||
$rank=$donor['rank'];
|
||||
}
|
||||
}
|
||||
foreach ($donor as $key => $value) {
|
||||
if($key='wus'){
|
||||
$wus=$donor['wus'];
|
||||
}
|
||||
}
|
||||
foreach ($donor as $key => $value) {
|
||||
if($key='credit'){
|
||||
$scores=$donor['credit'];
|
||||
}
|
||||
}
|
||||
foreach ($donor as $key => $value) {
|
||||
if($key='last'){
|
||||
$lastwus=$donor['last'];
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------//
|
||||
if($_GET['mode'] == 'advanced'){//判断是否是高级模式
|
||||
if($_GET['donor'] == null){
|
||||
echo '{"error":"10001"}';
|
||||
}elseif($_GET['team'] == null){
|
||||
echo '{"error":"10001"}';
|
||||
}else{
|
||||
if($_GET['height'] == null){//判断是否有提交画布大小
|
||||
if($_GET['weight'] == null){
|
||||
$canvas = imagecreatetruecolor(465, 92);//载入默认画布
|
||||
$weight = 465;
|
||||
$height = 95;
|
||||
$weightdefault = 465;
|
||||
$heightdefault = 95;
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}elseif($_GET['weight'] == null){
|
||||
if($_GET['height'] == null){
|
||||
$canvas = imagecreatetruecolor(465, 92);//载入默认画布
|
||||
$weight = 465;
|
||||
$height = 95;
|
||||
$weightdefault = 465;
|
||||
$heightdefault = 95;
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}else{
|
||||
$canvas = imagecreatetruecolor($_GET['weight'], $_GET['height']);//根据提交的参数载入画布
|
||||
$weightdefault = $_GET['weight'];
|
||||
$heightdefalut = $_GET['height'];
|
||||
}
|
||||
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
|
||||
imagefill($canvas, 0, 0, $background);//填充透明色
|
||||
imagecolortransparent($canvas, $background);//设置背景色
|
||||
if($_GET['fnt'] == null){//判断是否有提交自定义字体
|
||||
$text_fonts = 'fnt/default.ttf';//设置默认字体
|
||||
}else{
|
||||
$text_fonts = 'fnt/'.$_GET['fnt'];//根据提交的字体地址载入自定义字体
|
||||
}
|
||||
if($_GET['red'] == null){//判断是否有提交自定义字体颜色
|
||||
if($_GET['green'] == null){
|
||||
if($_GET['blue'] == null){
|
||||
$color = imagecolorallocate($canvas, 255, 255, 255);//设置默认文字颜色
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}else{
|
||||
if($_GET['green'] == null){
|
||||
}else{
|
||||
if($_GET['blue'] == null){
|
||||
}else{
|
||||
$color = imagecolorallocate($canvas, $_GET['red'], $_GET['green'], $_GET['blue']);//设置自定义文字颜色
|
||||
}
|
||||
}
|
||||
}
|
||||
if($_GET['textsize'] == null){//判断是否有提交自定义字体
|
||||
$text_size = 7;//设置默认字体大小
|
||||
}else{
|
||||
$text_size = $_GET['textsize'];//设置自定义字体大小
|
||||
}
|
||||
if($_GET['img'] == null){//判断是否有提交自定义底图
|
||||
$logo_url = 'img.png';//设置默认源图片
|
||||
}else{
|
||||
$logo_url = $_GET['img'];//设置自定义源图片
|
||||
}
|
||||
$logo = file_get_contents($logo_url);//读取源文件
|
||||
$logo_img = imagecreatefromstring($logo);//解析为图片
|
||||
if($_GET['imgx'] == null){//判断是否有提交自定义底图位置
|
||||
if($_GET['imgy'] == null){
|
||||
$imgx = 0;//设置默认底图位置
|
||||
$imgy = 0;
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}else{
|
||||
if($_GET['imgy'] == null){
|
||||
$error = 10001;
|
||||
}else{
|
||||
$imgx = $_GET['imgx'];//设置自定义底图位置
|
||||
$imgy = $_GET['imgy'];
|
||||
}
|
||||
}
|
||||
if($_GET['putweight'] == null){
|
||||
if($_GET['putheight'] == null){
|
||||
$weight = $weightdefault;
|
||||
$height = $heightdefault;
|
||||
}else{
|
||||
$error = 10001;
|
||||
}
|
||||
}else{
|
||||
if($_GET['putheight'] == null){
|
||||
$error = 10001;
|
||||
}else{
|
||||
$weight = $_GET['putweight'];
|
||||
$height = $_GET['putheight'];
|
||||
}
|
||||
}
|
||||
imagecopyresampled($canvas, $logo_img, $imgx, $imgy, 0, 0, $weight, $height, imagesx($logo_img), imagesy($logo_img));//覆盖图层
|
||||
//---------------------------------------------------------------------//
|
||||
//团队部分
|
||||
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名称
|
||||
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
|
||||
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
|
||||
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
|
||||
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
|
||||
//---------------------------------------------------------------------//
|
||||
//个人部分
|
||||
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
|
||||
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
|
||||
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
|
||||
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
|
||||
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
|
||||
//---------------------------------------------------------------------//
|
||||
if($error == null){//判断是否有错误
|
||||
header("content-type:image/png");//设置网页为图片
|
||||
imagepng($canvas);//输出图片
|
||||
imagedestroy($canvas);//关闭进程
|
||||
}elseif($error == 10001){
|
||||
header("Content-type:application/json;charset=utf-8");
|
||||
echo '{"error":"10001"}';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if($_GET['donor'] == null){
|
||||
header("Content-type:application/json;charset=utf-8");
|
||||
echo '{"error":"10001"}';
|
||||
}elseif($_GET['team'] == null){
|
||||
header("Content-type:application/json;charset=utf-8");
|
||||
echo '{"error":"10001"}';
|
||||
}else{
|
||||
$canvas = imagecreatetruecolor(465, 92);//载入画布
|
||||
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
|
||||
imagefill($canvas, 0, 0, $background);//填充透明色
|
||||
imagecolortransparent($canvas, $background);//设置背景色
|
||||
$text_fonts = 'fnt/default.ttf';//设置字体
|
||||
$color = imagecolorallocate($canvas, 255, 255, 255);//设置文字颜色
|
||||
$text_size = 7;//设置文字大小
|
||||
$logo_url = 'img.png';//设置源图片目录
|
||||
$logo = file_get_contents($logo_url);//读取源文件
|
||||
$logo_img = imagecreatefromstring($logo);//解析为图片
|
||||
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));//覆盖图层
|
||||
//---------------------------------------------------------------------//
|
||||
//团队部分
|
||||
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名
|
||||
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
|
||||
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
|
||||
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
|
||||
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
|
||||
//---------------------------------------------------------------------//
|
||||
//个人部分
|
||||
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
|
||||
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
|
||||
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
|
||||
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
|
||||
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
|
||||
//---------------------------------------------------------------------//
|
||||
header("content-type:image/png");//设置网页为图片
|
||||
imagepng($canvas);//输出图片
|
||||
imagedestroy($canvas);//关闭进程
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
header("Content-type:application/json;charset=utf-8");
|
||||
$stream_opts = [
|
||||
"ssl" => [
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false,
|
||||
]
|
||||
];
|
||||
$error = null;
|
||||
if($_GET['donor'] == null){
|
||||
if($_GET['team'] == '*'){
|
||||
echo @file_get_contents("http://reverse.ghink.net/fah.php?team=*",false, stream_context_create($stream_opts));
|
||||
}else{
|
||||
echo @file_get_contents("http://reverse.ghink.net/fah.php?team=".$_GET['team'],false, stream_context_create($stream_opts));
|
||||
}
|
||||
}else{
|
||||
if($_GET['team'] == null){
|
||||
}else{
|
||||
$error = '{"error":"10000"}';
|
||||
}
|
||||
}
|
||||
if($_GET['team'] == null){
|
||||
if($_GET['donor'] == '*'){
|
||||
echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=*",false, stream_context_create($stream_opts));
|
||||
}else{
|
||||
echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=".$_GET['donor'],false, stream_context_create($stream_opts));
|
||||
}
|
||||
}else{
|
||||
if($_GET['donor'] == null){
|
||||
}else{
|
||||
$error = '{"error":"10000"}';
|
||||
}
|
||||
}
|
||||
echo $error;
|
@ -1 +0,0 @@
|
||||
{"wikis": "https://gitee.com/ghink/api/wikis"}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
header("Content-type:text/html;charset=utf-8");
|
||||
$time=intval(time());
|
||||
if($_GET['type']==''){
|
||||
echo $time;
|
||||
}elseif($_GET['type']=='stamp'){
|
||||
echo $time;
|
||||
}elseif($_GET['type']=='date'){
|
||||
if($_GET['zone']==''){
|
||||
$time_gap=$time-(60*60*8)+(60*60*0);
|
||||
}elseif($_GET['zone']<=12 and $_GET['zone']>=-12){
|
||||
$time_gap=$time-(60*60*8)+(60*60*$_GET['zone']);
|
||||
}else{
|
||||
$error=true;
|
||||
}
|
||||
header("Content-type:application/json");
|
||||
if($error==true){
|
||||
echo '{"error":"10004"}';
|
||||
}else{
|
||||
echo '{"stamp":'.$time.',"year":"'.date("Y",$time_gap).'","month":"'.date("m",$time_gap).'","day":"'.date("d",$time_gap).'","hour":"'.date("H",$time_gap).'","minute":"'.date("i",$time_gap).'","second":"'.date("s",$time_gap).'"}';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user