Comments (13)
Hm, do you know where this is defined?
CREATE INDEX sensor_sensor_7a592b3b
ON public.sensor_sensor
USING btree
(sensor_type_id);
In any case, we might have to delete any INDEX
before performing step 2: moving primary key from sensor_id
to s_id
(integer key).
from friskby.
from friskby.
This is only step 1, yes. I'm still struggling with INDEX
issues. Perhaps the migration needs to drop all the indices:
Indexes:
"filter_filterdata_pkey" PRIMARY KEY, btree (id)
"filter_filterdata_sensor_id_6482fe566b49ce37_uniq" UNIQUE CONSTRAINT, btree (sensor_id, filter_code_id)
"filter_filterdata_ts_id_7167e05c2931e0a5_uniq" UNIQUE CONSTRAINT, btree (ts_id)
"filter_filterdata_4bd0d623" btree (filter_code_id)
"filter_filterdata_7ad5859e" btree (ts_id)
"filter_filterdata_d96d866a" btree (sensor_id)
"filter_filterdata_filter_code_id_cdca74721628e57_like" btree (filter_code_id varchar_pattern_ops)
"filter_filterdata_sensor_id_31261240c8b18c90_like" btree (sensor_id varchar_pattern_ops)
Foreign-key constraints:
"filt_ts_id_7167e05c2931e0a5_fk_time_series_regulartimeseries_id" FOREIGN KEY (ts_id) REFERENCES time_series_regulartimeseries(id) DEFERRABLE INITIALLY DEFERRED
"filter_filte_filter_code_id_cdca74721628e57_fk_filter_filter_id" FOREIGN KEY (filter_code_id) REFERENCES filter_filter(id) DEFERRABLE INITIALLY DEFERRED
"filter_filterdat_sensor_id_31261240c8b18c90_fk_sensor_sensor_id" FOREIGN KEY (sensor_id) REFERENCES sensor_sensor(sensor_id) DEFERRABLE INITIALLY DEFERRED
from friskby.
[...] I'm still struggling with INDEX issues.
Hehe - this stuff is beyond my SQL pay-grade
from friskby.
I've done it now locally.
I had to delete the filter*-tables, and I also deleted time_series* and plot-* tables.
from friskby.
def forwards(apps, schema_editor):
import sys
if not schema_editor.connection.alias == 'default':
return
sensor = apps.get_model('sensor', 'Sensor')
rawdata = apps.get_model('sensor', 'RawData')
sensors = {}
for row in sensor.objects.all():
sensor_name = row.sensor_id
sensor_id = row.s_id
sensors[sensor_name] = row
for row in rawdata.objects.all():
sensor_name = row.sensor_id
if sensor_name not in sensors:
sys.stderr.write('\nNo sensor for key "%s".\n' % sensor_name)
row.s_id = None
else:
row.s_id = sensors[sensor_name]
row.save()
With RawData
like:
class RawData(Model):
sensor_id = CharField(max_length=128)
s_id = ForeignKey( Sensor, null = True )
timestamp_recieved = DateTimeField( )
timestamp_data = DateTimeField( )
value = FloatField( default = -1 )
processed = BooleanField( default = False )
from friskby.
We need to create dummy sensors for
84 No sensor for key "OAMTempDHT22OJBrochsGate".
288 No sensor for key "ARUdustTest".
2055 No sensor for key "ARUtest".
7973 No sensor for key "OAMLysOJBrochsGate".
7974 No sensor for key "OAMFuktOJBrochsGate".
7974 No sensor for key "OAMStoevOJBrochsGate".
7974 No sensor for key "OAMTempOJBrochsGate".
413929 No sensor for key "NJBGassGroenllien".
But other than that, we're ready to go!
@joakim-hove Is it okay if we delete the filter-tables in the heroku db?
from friskby.
Delete delete!
When it comes to dummy sensors we might go the delete route instead?
from friskby.
Definitely. What's the gas sensor? Almost 500k rows?
from friskby.
The we can go back to, for each sensor,
def get_data_list(sensor, start, end):
data_all = RawData.objects.filter(s_id=sensor.s_id,
timestamp_data__range=
(start,end)).values("value",
"timestamp_data"
).order_by('timestamp_data')
datalist = downsample(list(data_all), minutes=30, cutoff=100)
datalist = map( make_timestamp , datalist )
return datalist
And we're more or less done with the migration. :)
from friskby.
Have performed the following steps upstream:
- make field
sensor.s_id
. - make field
sensor.s_id
be the primary key for theSensor
model. - created foreign key
rawdata.s_id
that formally links each rawdata entry to a sensor. (PR imminent)
The latter step is currently under testing at my machine. If successes galore, I will heroku push
and migrate. This step, however, takes appx 10 minutes (strange, but perhaps because it write 500k rows and tries to make it reversible?).
from friskby.
In fact, after indexing on rawdata.timestamp
(which we should consider),
min p10 p25 p50 p75 p90 max
before: 0.488 +/- 0.037, (0.430 0.450 0.460 0.480 0.500 0.540 0.660)
after: 0.466 +/- 0.039, (0.410 0.430 0.440 0.450 0.480 0.530 0.640)
morten: 0.369 +/- 0.029, (0.330 0.340 0.350 0.360 0.380 0.410 0.550)
current: 0.339 +/- 0.038, (0.300 0.310 0.320 0.330 0.340 0.380 0.810)
int_id: 0.265 +/- 0.020, (0.240 0.250 0.250 0.260 0.270 0.290 0.370)
indexed: 0.188 +/- 0.024, (0.160 0.170 0.170 0.180 0.190 0.210 0.300)
When we started way back in the beginning (before quick), we were at several seconds for SQL. Now we're down to less than 0.2s!
from friskby.
from friskby.
Related Issues (20)
- PM25 and PM10 columns in Quick are showing the same values HOT 2
- Quick Highchart Safari support HOT 14
- Wrong "last value" in status table HOT 1
- Midnight data received from BG sensors are interpreted +24h wrong HOT 9
- Consistent sorting of devices? HOT 2
- OpenLayers - map stretched initially HOT 3
- Remove space character from URLs HOT 6
- Merge friskby.no and http://friskby.herokuapp.com/ HOT 15
- Server error on front end trying to show PM2.5 HOT 1
- Make index on rawdata.timestamp HOT 3
- Consider removing the TimeStamp model HOT 2
- Setup of new devices
- Create custom raspbian-pi image with friskby pre-installed HOT 1
- API v1.0 HOT 5
- API for new device, new location for given device
- Accept posting without timestamp HOT 3
- API for location creation should respond properly
- API for location creation needs to be CSRF exempt
- Migrate from heroku
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from friskby.