Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
7ba3fec6
Commit
7ba3fec6
authored
Jan 30, 2015
by
Alan Mitchell
Browse files
Removed need for explicit database path in BMSdata class.
parent
95eb3fef
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
18 additions
and
16 deletions
+18
-16
bmsapp/global_vars.py
bmsapp/global_vars.py
+0
-3
bmsapp/readingdb/bmsdata.py
bmsapp/readingdb/bmsdata.py
+9
-2
bmsapp/readingdb/scripts/daily_status.py
bmsapp/readingdb/scripts/daily_status.py
+1
-2
bmsapp/readingdb/scripts/import_readings.py
bmsapp/readingdb/scripts/import_readings.py
+1
-2
bmsapp/reports/basechart.py
bmsapp/reports/basechart.py
+2
-2
bmsapp/scripts/calc_readings.py
bmsapp/scripts/calc_readings.py
+1
-1
bmsapp/storereads.py
bmsapp/storereads.py
+3
-3
bmsapp/views.py
bmsapp/views.py
+1
-1
No files found.
bmsapp/global_vars.py
View file @
7ba3fec6
...
...
@@ -6,9 +6,6 @@ from glob import glob
APP_PATH
=
realpath
(
dirname
(
__file__
))
# Full path to the database holding sensor readings
DATA_DB_FILENAME
=
join
(
APP_PATH
,
'data'
,
'bms_data.sqlite'
)
# Full path to the Django database holding project model data
# (building lists, sensor lists, etc.). Assume it is the first sqlite database
# in the directory above
...
...
bmsapp/readingdb/bmsdata.py
View file @
7ba3fec6
"""Class to encapsulate the BMON Reading database. Uses the SQLite database.
"""
import
sqlite3
,
sys
,
calendar
import
sqlite3
import
sys
import
calendar
import
os.path
import
pytz
from
dateutil
import
parser
# The path to the default Sqlite database used to store readings.
DEFAULT_DB
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
'bms_data.sqlite'
)
class
BMSdata
:
def
__init__
(
self
,
fname
):
def
__init__
(
self
,
fname
=
DEFAULT_DB
):
"""Creates the database object.
fname: full path to SQLite database file. If the file is not present,
it will be created.
...
...
bmsapp/readingdb/scripts/daily_status.py
View file @
7ba3fec6
...
...
@@ -7,7 +7,6 @@ os.chdir(os.path.dirname( os.path.abspath(sys.argv[0]) ))
sys
.
path
.
insert
(
0
,
'../'
)
# add the parent directory to the Python path
import
global_vars
from
readingdb
import
bmsdata
# make a logger object and set time zone so log readings are stamped with Alaska time.
...
...
@@ -24,6 +23,6 @@ except:
logger
=
logging
.
getLogger
(
'bms.daily_status'
)
# get a BMSdata object for the sensor reading database.
reading_db
=
bmsdata
.
BMSdata
(
global_vars
.
DATA_DB_FILENAME
)
reading_db
=
bmsdata
.
BMSdata
()
logger
.
info
(
'{:,} readings inserted in last day. {:,} total readings.'
.
format
(
reading_db
.
readingCount
(
time
.
time
()
-
3600
*
24
),
reading_db
.
readingCount
())
)
reading_db
.
close
()
bmsapp/readingdb/scripts/import_readings.py
View file @
7ba3fec6
...
...
@@ -29,10 +29,9 @@ import sys, glob
sys
.
path
.
insert
(
0
,
'../'
)
import
bmsapp.readingdb.bmsdata
import
bmsapp.global_vars
# Open reading database object
db
=
bmsapp
.
readingdb
.
bmsdata
.
BMSdata
(
bmsapp
.
global_vars
.
DATA_DB_FILENAME
)
db
=
bmsapp
.
readingdb
.
bmsdata
.
BMSdata
()
for
filename
in
glob
.
glob
(
sys
.
argv
[
1
]):
success_count
,
errors
=
db
.
import_text_file
(
filename
)
...
...
bmsapp/reports/basechart.py
View file @
7ba3fec6
...
...
@@ -4,7 +4,7 @@ Reports.
"""
import
time
,
logging
,
copy
,
importlib
from
django.conf
import
settings
import
bmsapp.models
,
bmsapp
.
global_vars
,
bmsapp
.
readingdb
.
bmsdata
import
bmsapp.models
,
bmsapp
.
readingdb
.
bmsdata
import
bmsapp.calcs.transforms
,
bmsapp
.
schedule
import
bmsapp.view_util
,
bmsapp
.
data_util
import
chart_config
...
...
@@ -132,7 +132,7 @@ class BaseChart(object):
# open the reading database and save it for use by the methods of this object.
# It is closed automatically in the destructor of the BMSdata class.
self
.
reading_db
=
bmsapp
.
readingdb
.
bmsdata
.
BMSdata
(
bmsapp
.
global_vars
.
DATA_DB_FILENAME
)
self
.
reading_db
=
bmsapp
.
readingdb
.
bmsdata
.
BMSdata
()
def
get_ts_range
(
self
):
"""
...
...
bmsapp/scripts/calc_readings.py
View file @
7ba3fec6
...
...
@@ -28,7 +28,7 @@ logger = logging.getLogger('bms.calc_readings')
# Readings object. Other calculated reading classes in addition to CalcReadingFuncs_01
# can be added to the list and they will be search for matching function names.
# Only allow calculated readings within the last 7 days.
reading_db
=
bmsdata
.
BMSdata
(
global_vars
.
DATA_DB_FILENAME
)
reading_db
=
bmsdata
.
BMSdata
()
calc
=
calcreadings
.
CalculateReadings
([
calcfuncs01
.
CalcReadingFuncs_01
,
],
reading_db
,
60
*
24
*
7
)
# get a database connection and cursor to the Django project database that has the sensor
...
...
bmsapp/storereads.py
View file @
7ba3fec6
...
...
@@ -4,7 +4,7 @@ Module used to store incoming sensor readings in the database.
import
dateutil.parser
,
calendar
,
re
,
time
import
models
,
global_vars
import
models
from
readingdb
import
bmsdata
from
calcs
import
transforms
...
...
@@ -59,7 +59,7 @@ def store(reading_id, request_data):
"""
# open the database
db
=
bmsdata
.
BMSdata
(
global_vars
.
DATA_DB_FILENAME
)
db
=
bmsdata
.
BMSdata
()
# parse the date into a datetime object and then into Unix seconds. Convert to
# integer.
...
...
@@ -94,7 +94,7 @@ def store_many(readings):
"""
# open the reading database
db
=
bmsdata
.
BMSdata
(
global_vars
.
DATA_DB_FILENAME
)
db
=
bmsdata
.
BMSdata
()
ts_lst
=
[]
reading_id_lst
=
[]
...
...
bmsapp/views.py
View file @
7ba3fec6
...
...
@@ -236,7 +236,7 @@ def get_readings(request, reading_id):
"""
# open the database
db
=
bmsdata
.
BMSdata
(
global_vars
.
DATA_DB_FILENAME
)
db
=
bmsdata
.
BMSdata
()
result
=
db
.
rowsForOneID
(
reading_id
)
return
HttpResponse
(
json
.
dumps
(
result
),
content_type
=
"application/json"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment