aanpassen aspx file

Forum over Homeseer Plugin ontwikkelingen, hierin staan aparte forums voor bijvoorbeeld Plugwise, RFXcom, Fritzbox, Alphatronics etc.

Moderator: Digit

aanpassen aspx file

Postby Edwin » Sun Dec 09, 2012 9:55 am

ik zou dit bestand aan willen passen om alleen het gas verbruik te zien van dit jaar .
ik krijg nu 90 dagen gasverbruik te zien en nog 2 andere tabellen. kan iemand mij vooruit helpen om dit te doen?
hier is het aspx bestand rfxutility365d.

alvast bedankt
edwin

***************************************************************************
<%@ Page Language="VB" EnableEventValidation="false" Debug="true" Trace="False" %>
<%@ Import Namespace="ChartDirector" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %>



<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>RFX Utility 365d</title>

<script runat="server">
Const swversion As String = "0.3" ' the version of this aspx page
'version 0.1
' initial version
'version 0.2
' steps corrected
'version 0.3
' array dimensions changed to accept another end date

Const DefaultPath As String = "C:\Program Files\HomeSeer 2\data\RFXCOM\RFXCOM.mdb"
Const INI_FILE As String = "hspi_RFXCOM.ini"

Public hs As Object
Public dbcomm As OleDbCommand
Public dbconn As New OleDbConnection

Public intNbrOfDays As Integer
Public dblCostDet(,) As Double
Public dblUsageDet(,) As Double
Public dblCost() As Double
Public dblUsage() As Double
Public dtToDate As DateTime

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
hs = Context.Items("Content")

intNbrOfDays = hs.GetINISetting("RFXChart", "UtilityDays", "365", INI_FILE)
dtToDate = Today() 'change this for another end date

ReDim dblCostDet(intNbrOfDays, 23)
ReDim dblUsageDet(intNbrOfDays, 23)
ReDim dblCost(intNbrOfDays)
ReDim dblUsage(intNbrOfDays)

'flags if device detected
Dim powerflag As Boolean
Dim gasflag As Boolean
Dim waterflag As Boolean

' The usage for the bar chart
Dim dblkWh0(intNbrOfDays - 1) As Double
Dim dblkWh1(intNbrOfDays - 1) As Double
Dim dblkWh2(intNbrOfDays - 1) As Double
Dim dblgas(intNbrOfDays - 1) As Double
Dim dblwater(intNbrOfDays - 1) As Double

' The labels for the bar chart
Dim strLabels(intNbrOfDays - 1) As String
Dim strDates As String = " "

'The device names
Dim device0 As String = ""
Dim device1 As String = ""
Dim device2 As String = ""
Dim gasdevice As String = "1"
Dim waterdevice As String = ""

Dim kwhcostdata As Double = 0
Dim kwhtotaluse As Double = 0
Dim kwhtotaldates As String = " "
Dim strKWH As String = ""

Dim gascostdata As Double = 0
Dim gastotaluse As Double = 0
Dim gastotaldates As String = " "
Dim strMQ As String = ""

Dim watercostdata As Double = 0
Dim watertotaluse As Double = 0
Dim watertotaldates As String = " "
Dim strLITER As String = ""

Dim i As Integer
Dim strDatabase As String
Dim sql As String
Dim pCount As Long = 0

Dim en As Object
Dim dv As Object
Dim dvcnt As Short = 0
Dim rfxsensor As String
Dim datDate As Date
Dim intStep As Integer
If intNbrOfDays <= 20 Then
intStep = 1
Else
intStep = Math.Round(intNbrOfDays \ 20 + 1)
End If
For i = 0 To (intNbrOfDays - 1) Step intStep
datDate = DateValue(DateAdd("d", -intNbrOfDays + 1 + i, dtToDate))
strLabels(i) = Day(datDate).ToString & "/" & Month(datDate).ToString
Next i

strDates = CStr(DateValue(DateAdd("d", 1 - intNbrOfDays, dtToDate))) & " to " & CStr(dtToDate)

strDatabase = Trim(hs.GetINISetting("RFXDatabase", "Path", DefaultPath, INI_FILE))
dbconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDatabase
dbconn.Open()

en = hs.GetDeviceEnumerator
Do While Not en.finished
dv = en.GetNext
If Not dv Is Nothing Then
If dv.interface = "RFXCOM" Then
If hs.GetINISetting("DeviceI" & dv.dc, "Chart", "No", INI_FILE) = "1" Then
Select Case Left(dv.name, 6).ToUpper
Case "RFXPWR"
powerflag = True
rfxsensor = dv.hc & dv.dc
dvcnt += 1

strKWH = hs.GetINISetting("DeviceI" & dv.dc, "Suffix", "kWh", INI_FILE)
sql = "SELECT rfxdate,rfxtime, rfxvalue, rfxcost FROM Power WHERE (rfxsensor='" & rfxsensor & "' AND (rfxdate>DateAdd('d',-" & intNbrOfDays.ToString & ",DateValue('" & dtToDate.ToString & "'))));"

GetValues(sql)

Select Case dvcnt
Case 1
For i = 0 To (intNbrOfDays - 1)
dblkWh0(i) = dblUsage(i)
kwhcostdata += dblCost(i)
kwhtotaluse += dblUsage(i)
Next
device0 = dv.hc & dv.dc & ":" & dv.Location & " - " & dv.name
Case 2
For i = 0 To (intNbrOfDays - 1)
dblkWh1(i) = dblUsage(i)
kwhcostdata += dblCost(i)
kwhtotaluse += dblUsage(i)
Next
device1 = dv.hc & dv.dc & ":" & dv.Location & " - " & dv.name
Case 3
For i = 0 To (intNbrOfDays - 1)
dblkWh2(i) = dblUsage(i)
kwhcostdata += dblCost(i)
kwhtotaluse += dblUsage(i)
Next
device2 = dv.hc & dv.dc & ":" & dv.Location & " - " & dv.name
Case Else
hs.WriteLog("Error", "RFXUtility365d" & intNbrOfDays.ToString & ".aspx, More then 3 RFXPwr found!")
End Select

Case "RFXGAS"
gasflag = True
rfxsensor = dv.hc & dv.dc

strMQ = hs.GetINISetting("DeviceI" & dv.dc, "Suffix", "m3", INI_FILE)
sql = "SELECT rfxdate, rfxtime, rfxvalue, rfxcost FROM Gas WHERE (rfxsensor='" & rfxsensor & "' AND (rfxdate>DateAdd('d',-" & intNbrOfDays.ToString & ",DateValue('" & dtToDate.ToString & "'))));"
GetValues(sql)
For i = 0 To (intNbrOfDays - 1)
dblgas(i) = dblUsage(i)
gascostdata += dblCost(i)
gastotaluse += dblUsage(i)
Next
gasdevice = dv.hc & dv.dc & ":" & dv.Location & " - " & dv.name

Case "RFXWAT"
waterflag = True
rfxsensor = dv.hc & dv.dc

strLITER = hs.GetINISetting("DeviceI" & dv.dc, "Suffix", "lt", INI_FILE)
sql = "SELECT rfxdate, rfxtime, rfxvalue, rfxcost FROM Water WHERE (rfxsensor='" & rfxsensor & "' AND (rfxdate>DateAdd('d',-" & intNbrOfDays.ToString & ",DateValue('" & dtToDate.ToString & "'))));"
GetValues(sql)
For i = 0 To (intNbrOfDays - 1)
dblwater(i) = dblUsage(i)
watercostdata += dblCost(i)
watertotaluse += dblUsage(i)
Next
waterdevice = dv.hc & dv.dc & ":" & dv.Location & " - " & dv.name
End Select
End If
End If
End If
Loop

dbconn.Close()

' Create a kwh XYChart object of size 880 x 300 pixels
Dim c1 As XYChart = New XYChart(880, 300, Chart.goldColor, -1, 2)
With c1
If powerflag Then
' Add a stacked bar layer
Dim layer As BarLayer = .addBarLayer(Chart.Stack)

.addText(800, 30, "Version: " & swversion)

' Set the plotarea at (50, 50) and of size 600 x 200 pixels
.setPlotArea(50, 50, 600, 200)

' Add a legend box at (680, 50)
.addLegend(680, 50, False)

' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("Power usage at " & strDates & " in " & strKWH, "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)

' Set the kwhlabels on the x axis
.xAxis().setLabels(strLabels)
.xAxis().setTitle("Day")

' Add a title to the primary (left) y axis
.yAxis().setTitle(strKWH)

' Set the y axis to scale from 0 to 4, with mayor ticks every units
'.yAxis().setLinearScale(0, 4, 1, 0.5)

.addText(680, 200, "Totals last " & intNbrOfDays & "days:", "bold", 10)
.addText(690, 220, "Cost : " & FormatCurrency(kwhcostdata, 2))
.addText(690, 240, "Power: " & CStr(Math.Round(kwhtotaluse, 2)) & " " & strKWH)

' Add the three data sets to the bar layer
If device0 <> "" Then
layer.addDataSet(dblkWh0, &HFF8080, device0)
End If
If device1 <> "" Then
layer.addDataSet(dblkWh1, &H80FF80, device1)
End If
If device2 <> "" Then
layer.addDataSet(dblkWh2, &H8080FF, device2)
End If
Else
' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("No power sensor available", "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)
End If
' output the chart
WebChartViewer1.Image = .makeWebImage(Chart.PNG)

' Include tool tip for the chart
WebChartViewer1.ImageMap = .getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} " & strKWH & "'")
End With 'c1


' Create a gas XYChart object of size 880 x 300 pixels
Dim c2 As XYChart = New XYChart(880, 300, Chart.silverColor, -1, 2)
With c2
If gasflag Then
' Add a stacked bar layer
Dim gaslayer As BarLayer = .addBarLayer()

.addText(800, 30, "Version: " & swversion)

' Set the plotarea at (50, 50) and of size 600 x 200 pixels
.setPlotArea(50, 50, 600, 200)

' Add a legend box at (680, 50)
.addLegend(680, 50, False)

' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("Gas usage at " & strDates & " in " & strMQ, "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)

' Set the gaslabels on the x axis
.xAxis().setLabels(strLabels)
.xAxis().setTitle("Day")

' Add a title to the primary (left) y axis
.yAxis().setTitle(strMQ)

.addText(680, 200, "Totals last " & intNbrOfDays & "days:", "bold", 10)
.addText(690, 220, "Cost : " & FormatCurrency(gascostdata, 2))
.addText(690, 240, "Gas : " & CStr(Math.Round(gastotaluse, 2)) & " " & strMQ)

' Add the data set to the bar layer
gaslayer.addDataSet(dblgas, &HFF8080, gasdevice)
Else
' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("No gas sensor available", "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)
End If
' output the chart
WebChartViewer2.Image = .makeWebImage(Chart.PNG)

' Include tool tip for the chart
WebChartViewer2.ImageMap = .getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} " & strMQ & "'")
End With 'c2

' Create a water XYChart object of size 880 x 300 pixels
Dim c3 As XYChart = New XYChart(880, 300, Chart.goldColor, -1, 2)
With c3
If waterflag Then
' Add a stacked bar layer
Dim waterlayer As BarLayer = .addBarLayer()

.addText(800, 30, "Version: " & swversion)

' Set the plotarea at (50, 50) and of size 600 x 200 pixels
.setPlotArea(50, 50, 600, 200)

' Add a legend box at (680, 50)
.addLegend(680, 50, False)

' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("water usage at " & strDates & " in " & strLITER, "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)

' Set the waterlabels on the x axis
.xAxis().setLabels(strLabels)
.xAxis().setTitle("Day")

' Add a title to the primary (left) y axis
.yAxis().setTitle(strLITER)

.addText(680, 200, "Totals last " & intNbrOfDays & "days:", "bold", 10)
.addText(690, 220, "Cost : " & FormatCurrency(watercostdata, 2))
.addText(690, 240, "water : " & CStr(Math.Round(watertotaluse, 2)) & " " & strLITER)

' Add the data set to the bar layer
waterlayer.addDataSet(dblwater, &HFF8080, waterdevice)
Else
' Add a title to the chart using 14 points Times Bold Itatic font and a metal background
.addTitle("No water sensor available", "Times New Roman Bold Italic", 14).setBackground(Chart.metalColor(&H9999FF), -1, 1)
End If

' output the chart
WebChartViewer3.Image = .makeWebImage(Chart.PNG)

' Include tool tip for the chart
WebChartViewer3.ImageMap = .getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} " & strLITER & "'")
End With 'c3
End Sub

Sub GetValues(ByVal sql As String)
Dim i, j As Integer
Dim dbread As OleDbDataReader

dbcomm = New OleDbCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
If dbread.HasRows Then
For i = 0 To (intNbrOfDays - 1)
dblUsage(i) = 0
dblCost(i) = 0
For j = 0 To 23
dblUsageDet(i, j) = 0
Next j
Next i

'get all data from the database
Do While dbread.Read()
i = (intNbrOfDays - 1) - DateDiff(DateInterval.Day, DateValue(dbread("rfxdate")), dtToDate)
j = Hour(dbread("rfxtime"))
If dblUsageDet(i, j) = 0 Then
dblUsageDet(i, j) = dbread("rfxvalue")
dblCostDet(i, j) = dbread("rfxcost")
ElseIf dbread("rfxvalue") < dblUsageDet(i, j) Then 'store the lowest counter value
dblUsageDet(i, j) = dbread("rfxvalue")
dblCostDet(i, j) = dbread("rfxcost")
End If
Loop
End If
dbread.Close()

'calculate the daily costs
For i = 0 To (intNbrOfDays - 2)
For j = 0 To 22
If dblUsageDet(i, j) <> 0 Then
If dblUsageDet(i, j + 1) <> 0 Then
dblCost(i) += (dblUsageDet(i, j + 1) - dblUsageDet(i, j)) * dblCostDet(i, j + 1)
Else
dblUsageDet(i, j + 1) = dblUsageDet(i, j)
End If
End If
Next j
If dblUsageDet(i, j) <> 0 Then
If dblUsageDet(i + 1, 0) <> 0 Then
dblCost(i) += (dblUsageDet(i + 1, 0) - dblUsageDet(i, 23)) * dblCostDet(i + 1, 0)
Else
dblUsageDet(i + 1, 0) = dblUsageDet(i, 23)
End If
End If
Next i

For i = 0 To (intNbrOfDays - 2)
If dblUsageDet(i, 0) <> 0 Then
dblUsage(i) = dblUsageDet(i + 1, 0) - dblUsageDet(i, 0)
End If
Next i

For i = 23 To 0 Step -1
If dblUsageDet(intNbrOfDays - 1, i) <> 0 Then
For j = 0 To (i - 1)
dblCost(intNbrOfDays - 1) += (dblUsageDet(intNbrOfDays - 1, j + 1) - dblUsageDet(intNbrOfDays - 1, j)) * dblCostDet(intNbrOfDays - 1, j + 1)
Next j
dblUsage(intNbrOfDays - 1) = dblUsageDet(intNbrOfDays - 1, i) - dblUsageDet(intNbrOfDays - 1, 0)
Exit For
End If
Next i
End Sub

Function PageHeader() As String
Return hs.GetPageHeader("RFX Utility " & intNbrOfDays & " days", "", "GetSizeWH();", False, False, False, False, False)
End Function
</script>

<%
Response.Write(PageHeader)
%>

</head>
<body>
<chart:WebChartViewer id="WebChartViewer1" runat="server" />
<br />
<br />
<chart:WebChartViewer id="WebChartViewer2" runat="server" />
<br />
<br />
<chart:WebChartViewer id="WebChartViewer3" runat="server" />
<br />
<br />
<img src="/RFXCOM/images/rfxcom.jpg" alt="RFXCOM" />
</body>
</html>
Edwin
Member
Member
 
Posts: 447
Joined: October 2007
Location: Netherlands

Re: aanpassen aspx file

Postby AshaiRey » Mon Dec 10, 2012 9:39 am

Heb je al wat geprobeerd en zo ja wat lukt niet en waarom?
Sorry, maar ik ga niet je werk doen. Ik wil je daarin tegen wel op weg helpen zodat je toekomstige aanpassingen zelf kan.

Kijk hier eens naar
Welk ini file wordt er gebruikt?
-> Const INI_FILE As String = "hspi_RFXCOM.ini"
(csidata.com/custserv/onlinehelp/vbsdocs ... s/vbs5.htm)

Hmmm, intNbrOfDays lijkt wel veel op wat jij zoekt.
Wat doet deze?
-> intNbrOfDays = hs.GetINISetting("RFXChart", "UtilityDays", "365", INI_FILE)
(homeseer.com/support/homeseer/WebHelp2/ ... meseer.htm)
Daar staat ook vermeld waar je het ini file kan vinden.
Pas die waarde aan en kijk wat er dan gebeurd.

En dan 2 andere tabellen? Beetje vaag.
Ik moet dus gaan uitzoeken welke tabellen dat zijn. Ik neem aan water en electra omdat je hiet gas noemt.
Die twee blokken code kan je gewoon weghalen en dan komen de tabellen er niet meer. Je kan de code ook laten staan en dan moet je een ' of het woord rem voor iedere regel zetten die je wilt uitschakelen. Welke blokken zijn het? Dat staat in de code duidelijk aangegeven.
Tip: vanaf de regel vor With c<x> tot en met End With c<x>
Bram
AshaiRey
Senior Member
Senior Member
 
Posts: 1301
Joined: February 2009
Location: Netherlands

Re: aanpassen aspx file

Postby Edwin » Mon Dec 10, 2012 12:10 pm

Bedankt voor je hulp, het was zeker niet de bedoeling dat je alles voor me ging doen,alleen een beetje op weg helpen.
Dat is hierbij gelukt en ga ermee aan het werk.
Groeten
Edwin
.
Edwin
Member
Member
 
Posts: 447
Joined: October 2007
Location: Netherlands

Re: aanpassen aspx file

Postby AshaiRey » Mon Dec 10, 2012 12:55 pm

Gelukkig vat je het goed op. :-)
Mocht je verder hulp nodig hebben dan hoor ik het wel, maar ik denk dat je het zo wel kan opknappen en wat je ervan op steekt is nooit weg voor je volgende probleem.
Bram
AshaiRey
Senior Member
Senior Member
 
Posts: 1301
Joined: February 2009
Location: Netherlands


Return to Homeseer Plugins Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron