Script HTML:Aff données solaires

Un article de MacodaWiki.

Jump to: navigation, search

Description

Ce script ASP est exécuté sur le serveur Web Homeseer et permet d'afficher les données stockées dans une base de données SQL par le script compteur_solaire.vbs, associé au montage Compteur solaire.

Attention, le script n'est pas tout à fait propre, mais il est opérationnel.

Résultat

-

Script

<%@ LANGUAGE=VBScript %>
<%

res=Request.QueryString("res")


' NomImg    : Nom du fichier image (png) qui sera genere
'              gnration pour le web 

'Détermine l'adresse de l'utilisateur
userID = request.servervariables("REMOTE_ADDR")
if (userID = "127.0.0.1") or (InStr(userID,"localhost")) then
	sAdrHttpSrv = "localhost"
elseif (instr(userID,"192.168.")) then
	sAdrHttpSrv = "192.168.0.1"
else
	sAdrHttpSrv = "www.macoda.com"
	hs.writelog "http-aff_solaire.asp" , "Connexion de l'ordinateur sur aff_solaire.ASP => "&userID

	hs.writelog "http-aff_solaire.asp" , "ATD => Faire une bibliothque de fonction HTML"
	hs.writelog "http-aff_solaire.asp" , "ATD => Si adresse IP = 196.28.29.89 alors PC_BUREAU_CNRS"
end if


'***********
'***********
'***********
'***********
'***********


'******************************************************************************************
'******************************************************************************************
'******************************************************************************************

Sub Construit_Graphique(NomImg,jour_aff,mois_aff,annee_aff,heure_aff_min,heure_aff_max,min_voltage,max_voltage,niv_debug)
	   if (niv_debug = 1) then 
response.write "
"
	   	response.write "NomImg = "&NomImg&"
" end if ' une image sera crée pour la priode J3 J1 J1 = Date ' aujourd'hui Dt = DateAdd("d", 0, Date) T1 = DateSerial(annee_aff, mois_aff, jour_aff) T1 = dayname(T1) & " " & T1 'titre du graphique Dt = DateAdd("d", 1, Date) 'aujourd'hui + 1 jour pour aller jusqu'a 23h59 J1 = Year(Dt) & "," & Month(Dt) & "," & Day(Dt) 'format 2004,05,25 J3_1 = annee_aff & "," & mois_aff & "," & jour_aff 'format 2004,05,25 J3_2 = annee_aff & "," & mois_aff & "," & jour_aff+1 'format 2004,05,25 '****************************************************************************************** 'appel de chartDirector api Set cd = CreateObject("ChartDirector.API") 'taille de l'image Set c = cd.XYChart(lg_graph, ht_graph) Call c.setBackground(&H9c9cce, &H9c9cce, 2) Call c.setPlotArea(40, 30, lg_graph-55, ht_graph-80, &HFFFFFF, &HFFFFFF, &HC0C0C0, &HC0C0C0) Call c.addTitle(T1 & " " & "Voltage", "timesbi.ttf").setBackground(&H9c9cce) ' 8 => Taille de la police de caractre pour la lgende Call c.addLegend(55, 25, False, "", 8).setBackground(cd.Transparent) ' response.write "De " & J1 & " " & J3 & " soit "& x &" jours
" ' response.write "Pour "&J3 & "
" Dim lay(10) 'maximum 10 courbes donc 10 devices 1-Wire!!! Set Base = CreateObject("ADODB.Connection") Set rsT = CreateObject("ADODB.Recordset") Base.Open "HOMESEER" SQL = "Select Voltage, DATE_OP From tb_solaire Where " SQL = SQL & "DATE_OP>=DateSerial("&J3_1&") AND DATE_OP<DateSerial("&J3_2&") AND Hour([DATE_OP])>="&cstr(heure_aff_min)&" AND Hour([DATE_OP])<="&cstr(heure_aff_max)&" ORDER BY DATE_OP" if (niv_debug = 1) then response.write j&" : " &SQL &"
" end if Call rsT.Open(SQL, Base) Set dbTableT = cd.DBTable(rsT) rsT.Close() Set lay(j) = c.addSplineLayer(dbTableT.getCol(0), &H33FF33, LocatTemp) Call lay(j).setXData(dbTableT.getCol(1)) Call c.xAxis().setWidth(2) Call c.yAxis().setWidth(2) Ecart = (max_voltage-min_voltage)/10 Call c.yAxis().setLinearScale(min_voltage, max_voltage, Ecart) Call c.yAxis().setLabelFormat("{value}") Call c.makeChart("\program files\HomeSeer\html\" & NomImg) End Sub '****************************************************************************************** '****************************************************************************************** '****************************************************************************************** Sub goTemp(NomImg, zone_db,jour_aff,mois_aff,annee_aff,min_heure,max_heure,min_voltage,max_voltage,niv_debug) if (niv_debug = 1) then
response.write "
"
	   	response.write "NomImg = "&NomImg&"
" response.write "jour_aff = "&jour_aff&"
" response.write "mois_aff = "&mois_aff&"
" response.write "annee_aff = "&annee_aff&"
" response.write "heure_aff_min = "&min_heure&"
" response.write "heure_aff_max = "&max_heure&"
" end if ' une image sera crée pour la priode J3 J1 T1 = DateSerial(annee_aff, mois_aff, jour_aff) T1 = dayname(T1) & " " & T1 'titre du graphique J1 = "#" & cstr(mois_aff) & "/" & cstr(jour_aff) & "/" & cstr(annee_aff) & "#" jour_aff2 = jour_aff-1 mois_aff2 = mois_aff if (jour_aff2 = 0) then jour_aff2 = 31 mois_aff2 = mois_aff2-1 end if jour_aff3 = jour_aff2-1 mois_aff3 = mois_aff2 if (jour_aff3 = 0) then jour_aff3 = 31 mois_aff3 = mois_aff3-1 end if J2 = "#" & cstr(mois_aff2) & "/" & cstr(jour_aff2) & "/" & cstr(annee_aff) & "#" J3 = "#" & cstr(mois_aff3) & "/" & cstr(jour_aff3) & "/" & cstr(annee_aff) & "#" if (jour_aff+1>31) then J1_2 = "#" & cstr(mois_aff+1) & "/" & cstr(1) & "/" & cstr(annee_aff) & "#" J2_2 = "#" & cstr(mois_aff2) & "/" & cstr(jour_aff2) & "/" & cstr(annee_aff) & "#" J3_2 = "#" & cstr(mois_aff3) & "/" & cstr(jour_aff3) & "/" & cstr(annee_aff) & "#" else J1_2 = "#" & cstr(mois_aff) & "/" & cstr(jour_aff+1) & "/" & cstr(annee_aff) & "#" J2_2 = "#" & cstr(mois_aff2) & "/" & cstr(jour_aff2+1) & "/" & cstr(annee_aff) & "#" J3_2 = "#" & cstr(mois_aff3) & "/" & cstr(jour_aff3+1) & "/" & cstr(annee_aff) & "#" end if '****************************************************************************************** 'appel de chartDirector api Set cd = CreateObject("ChartDirector.API") 'taille de l'image Set c = cd.XYChart(lg_graph, ht_graph) Call c.setBackground(&H9c9cce, &H9c9cce, 2) Call c.setPlotArea(40, 30, lg_graph-55, ht_graph-80, &HFFFFFF, &HFFFFFF, &HC0C0C0, &HC0C0C0) Call c.addTitle(T1 & " " & zone_db, "timesbi.ttf").setBackground(&H9c9cce) ' 8 => Taille de la police de caractre pour la lgende Call c.addLegend(55, 25, False, "", 8).setBackground(cd.Transparent) ' response.write "De " & J1 & " " & J3 & " soit "& x &" jours - table : " & table & "
" ' response.write "Pour "&J3 & "
" Dim lay(10) 'maximum 10 courbes donc 10 devices 1-Wire!!! Dim cou(10) cou(0) = &H808080ff cou(1) = &H80ff0000 cou(2) = &H8000ff00 ' cou(0) = &HFFFF33 ' cou(1) = &H33FF33 ' cou(2) = &HFF3333 cou(3) = &HFF33FF cou(4) = &H3333FF cou(5) = &HAA33FF cou(6) = &H33AAFF cou(7) = &HAAAAFF cou(8) = &HAA33AA cou(9) = &H33FFFF j = 1 ' ouverture base de donnee systeme ou sont stockees les temperatures ' HomeSeer est cree avec odbcad32.exe : BdD systeme pointant sur un fichier ' xxxxx.mdb ' ' un champ NOM : contient les temperatures (string) ' LOCAT : nom du device 1 wire (tronqu 12 car) (string(12)) ' DATE : la date de la mesure ' Set Base = CreateObject("ADODB.Connection") Set rsT = CreateObject("ADODB.Recordset") Base.Open "HOMESEER" ' Le second argument représente la "profondeur" des colonnes Set layer = c.addBarLayer2(cd.Side, 10) j = 0 For j = 0 To 2 str_date="'dd/mm/yyyy h:""00""'" if (j=0) then SQL = "SELECT avg([voltage]) AS VOLTAGE_AFF, CDate(Format([date_op],"&str_date&")) AS Date_reg FROM tb_solaire GROUP BY CDate(Format([date_op],"&str_date&")) HAVING (((First(Date_op))>="&J1&" And (First(Date_op))< "&J1_2&")) ORDER BY CDate(Format([date_op],"&str_date&"))" if (j=1) then SQL = "SELECT avg([voltage]) AS VOLTAGE_AFF, CDate(Format([date_op],"&str_date&")) AS Date_reg FROM tb_solaire GROUP BY CDate(Format([date_op],"&str_date&")) HAVING (((First(Date_op))>="&J2&" And (First(Date_op))< "&J2_2&")) ORDER BY CDate(Format([date_op],"&str_date&"))" if (j=2) then SQL = "SELECT avg([voltage]) AS VOLTAGE_AFF, CDate(Format([date_op],"&str_date&")) AS Date_reg FROM tb_solaire GROUP BY CDate(Format([date_op],"&str_date&")) HAVING (((First(Date_op))>="&J3&" And (First(Date_op))< "&J3_2&")) ORDER BY CDate(Format([date_op],"&str_date&"))" Call rsT.Open(SQL, Base) Set dbTableT = cd.DBTable(rsT) ' ATD response.write j&" : " &SQL &"
" if (niv_debug = 1) then response.write j&" : " &SQL &"
" end if Call c.xAxis().setLabels(dbTableT.getCol(1)) Call c.xAxis().setLabelFormat("{value|mm/dd}") Call c.xAxis().setLabelStyle("", 8, 0, 45) if (j=0) then ' Call layer.addDataSet(dbTableT.getCol(0), cou(j), zone_db) Call c.addBarLayer(dbTableT.getCol(0), cou(j), zone_db, 5) else ' Call layer.addDataSet(dbTableT.getCol(0), cou(j), zone_db&" j-"&cstr(j)) Call c.addBarLayer(dbTableT.getCol(0), cou(j), zone_db&" j-"&cstr(j), 5) end if rsT.Close() Next Call c.xAxis().setWidth(2) ' Call c.xAxis().setLinearScale(0, 25, 5) Call c.yAxis().setWidth(2) coord_min = min_voltage coord_max = max_voltage Ecart = (max_voltage-min_voltage)/10 Call c.yAxis().setLinearScale(cDbl(coord_min), cDbl(coord_max), Ecart) Call c.yAxis().setLabelFormat("{value}") Call c.makeChart("\program files\HomeSeer\html\" & NomImg) End Sub '****************************************************************************************** '****************************************************************************************** '****************************************************************************************** Function dayname(madate) Dim t, j t = "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi" j = Split(t, ",", -1, 1) dayname = j(Weekday(madate) - 1) End Function '*********** '*********** '*********** '*********** '*********** %> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <meta HTTP-EQUIV="EXPIRES" CONTENT="0"> <meta HTTP-EQUIV="Pragma" CONTENT="no-cache"> <title>Analyse Voltage solaire</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <script language="javascript"> if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } res = "res="+myWidth+"x"+myHeight </script> <% res=request.form("res") if res = "" then response.write "<script language='javascript'>" response.write "top.location.href='aff_solaire.asp?'+res" response.write "</script>" end if jour=request.form("jour") mois=request.form("mois") annee=request.form("annee") min_heure=request.form("min_heure") max_heure=request.form("max_heure") min_voltage=request.form("min_voltage") max_voltage=request.form("max_voltage") if max_heure ="" then Dt = DateAdd("d", 0, Date) jour = Day(Dt) mois = month(Dt) annee = Year(Dt) min_heure = 00 max_heure = 24 min_voltage = 0 max_voltage = 5 end if %> <% NIV_DEBUG_PAS = 0 NIV_DEBUG_AVEC = 1 iPosX=instr(1,res,"x") sLargeur = mid(res,1,iPosX-1) sHauteur = mid(res,iPosX+1,99) Nb_Graphique = 2 ht_graph = ( Cdbl(sHauteur) / Nb_Graphique)-50 lg_graph = Cdbl(sLargeur) - 50 Construit_Graphique "hb_Solaire_Courbe.png", jour,mois,annee,min_heure,max_heure,min_voltage,max_voltage,NIV_DEBUG_PAS goTemp "hb_solaire_Voltage_Heure.png","Voltage",jour,mois,annee,min_heure,max_heure,min_voltage,max_voltage,NIV_DEBUG_SANS if res <> "" then response.write "<img src=hb_Solaire_Courbe.png >

" response.write "<img src=hb_solaire_Voltage_Heure.png >
" end if sText ="<form method='post' name='formulaire' action='aff_solaire.asp?res="&res&"'>" response.write sText %>

Date <input type="text" name="jour" value="<%=jour%>" size = 2> / <input type="text" name="mois" value="<%=mois%>" size = 2> / <input type="text" name="annee" value="<%=annee%>" size = 4> Heure minimum <input type="text" name="min_heure" value="<%=min_heure%>" > - Heure maximum <input type="text" name="max_heure" value="<%=max_heure%>" >
Voltage minimum <input type="text" name="min_voltage" value="<%=min_voltage%>" > - Voltage maximum <input type="text" name="max_voltage" value="<%=max_voltage%>" >
<% response.write "<input type='hidden' name='res' value='"&res'>" %> <input type="submit"> </form> </body> </html>