-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
1220 lines (958 loc) · 38.9 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import random
from uuid import uuid4
from django.db import models
from django.db.models import Sum
from django.contrib.gis.db import models as geomodels
from django.contrib.postgres.fields import JSONField
from django.utils import timezone
from stemp_abw.app_settings import labels
# class MapLayers(models.Model):
# model_label = models.CharField(max_length=20)
# caption = models.CharField(max_length=50)
# description = models.CharField(max_length=100)
#############################
# Layer models (status quo) #
#############################
class LayerModel(models.Model):
class Meta:
abstract = True
@property
def name(self):
raise NotImplementedError
def __str__(self):
return '{name} Objekt ({pk_name}={pk})'.format(
name=labels()['layers'][self.name]['title'],
pk_name=self._meta.pk.name,
pk=self.pk)
class RpAbwBound(LayerModel):
name = 'rpabw'
geom = geomodels.MultiLineStringField(srid=4326, null=True)
class RegMun(LayerModel):
name = 'reg_mun'
ags = models.IntegerField(primary_key=True)
geom = geomodels.MultiPolygonField(srid=3035)
geom_centroid = geomodels.PointField(srid=3035, null=True)
gen = models.CharField(max_length=254)
class RegMunPop(RegMun):
"""This is a proxy model for RegMun which got same relations to the DB
table but changes the model name. This is needed to load the appropriate
DetailView when clicking on a map feature (serialized property in the data
view).
- See Also: https://github.com/rl-institut/WAM_APP_stemp_abw/issues/2
- All other model classes which heir from RegMun work like this.
"""
name = 'reg_mun_pop'
class Meta:
proxy = True
@property
def pop(self):
return self.mundata.pop_2017
@property
def pop_region(self):
return MunData.objects.aggregate(Sum('pop_2017'))['pop_2017__sum']
class RegMunPopDensity(RegMunPop):
name = 'reg_mun_pop_density'
class Meta:
proxy = True
@property
def pop_density(self):
return round(self.mundata.pop_2017 / self.mundata.area)
@property
def area_region(self):
return MunData.objects.aggregate(Sum('area'))['area__sum']
@property
def pop_density_region(self):
return round(self.pop_region / self.area_region)
class RegMunGenEnergyRe(RegMun):
name = 'reg_mun_gen_energy_re'
class Meta:
proxy = True
@property
def gen_energy_re(self):
return round((self.mundata.gen_el_energy_wind +
self.mundata.gen_el_energy_pv_roof +
self.mundata.gen_el_energy_pv_ground +
self.mundata.gen_el_energy_hydro +
self.mundata.gen_el_energy_bio) / 1e3)
@property
def gen_energy_re_region(self):
result = MunData.objects.aggregate(Sum('gen_el_energy_wind'))['gen_el_energy_wind__sum'] + \
MunData.objects.aggregate(Sum('gen_el_energy_pv_roof'))['gen_el_energy_pv_roof__sum'] + \
MunData.objects.aggregate(Sum('gen_el_energy_pv_ground'))['gen_el_energy_pv_ground__sum'] + \
MunData.objects.aggregate(Sum('gen_el_energy_hydro'))['gen_el_energy_hydro__sum'] + \
MunData.objects.aggregate(Sum('gen_el_energy_bio'))['gen_el_energy_bio__sum']
return round(result / 1e3)
class RegMunDemElEnergy(RegMun):
name = 'reg_mun_dem_el_energy'
class Meta:
proxy = True
@property
def dem_el_energy(self):
return round((self.mundata.dem_el_energy_hh +
self.mundata.dem_el_energy_rca +
self.mundata.dem_el_energy_ind) / 1e3)
@property
def dem_el_energy_region(self):
result = MunData.objects.aggregate(Sum('dem_el_energy_hh'))['dem_el_energy_hh__sum'] + \
MunData.objects.aggregate(Sum('dem_el_energy_rca'))['dem_el_energy_rca__sum'] + \
MunData.objects.aggregate(Sum('dem_el_energy_ind'))['dem_el_energy_ind__sum']
return round(result / 1e3)
class RegMunEnergyReElDemShare(RegMunGenEnergyRe, RegMunDemElEnergy):
name = 'reg_mun_energy_re_el_dem_share'
class Meta:
proxy = True
@property
def energy_re_el_dem_share(self):
return round(self.gen_energy_re / self.dem_el_energy * 100)
@property
def energy_re_el_dem_share_region(self):
return round(self.gen_energy_re_region / self.dem_el_energy_region * 100)
class RegMunGenEnergyRePerCapita(RegMunGenEnergyRe, RegMunPop):
name = 'reg_mun_gen_energy_re_per_capita'
class Meta:
proxy = True
@property
def gen_energy_re_per_capita(self):
return round(self.gen_energy_re * 1e3 / self.mundata.pop_2017, 1)
@property
def gen_energy_re_per_capita_region(self):
return round(self.gen_energy_re_region * 1e3 / self.pop_region, 1)
class RegMunGenEnergyReDensity(RegMunGenEnergyRe, RegMunPopDensity):
name = 'reg_mun_gen_energy_re_density'
class Meta:
proxy = True
@property
def gen_energy_re_density(self):
return round(self.gen_energy_re * 1e3 / self.mundata.area, 1)
@property
def gen_energy_re_density_region(self):
return round(self.gen_energy_re_region * 1e3 / self.area_region, 1)
class RegMunGenCapRe(RegMun):
name = 'reg_mun_gen_cap_re'
class Meta:
proxy = True
@property
def gen_cap_re(self):
return round(self.mundata.gen_capacity_wind +
self.mundata.gen_capacity_pv_roof_large +
self.mundata.gen_capacity_pv_ground +
self.mundata.gen_capacity_hydro +
self.mundata.gen_capacity_bio)
@property
def gen_cap_re_region(self):
result = MunData.objects.aggregate(Sum('gen_capacity_wind'))['gen_capacity_wind__sum'] + \
MunData.objects.aggregate(Sum('gen_capacity_pv_roof_large'))['gen_capacity_pv_roof_large__sum'] + \
MunData.objects.aggregate(Sum('gen_capacity_pv_ground'))['gen_capacity_pv_ground__sum'] + \
MunData.objects.aggregate(Sum('gen_capacity_hydro'))['gen_capacity_hydro__sum'] + \
MunData.objects.aggregate(Sum('gen_capacity_bio'))['gen_capacity_bio__sum']
return round(result)
class RegMunGenCapReDensity(RegMunGenCapRe, RegMunPopDensity):
name = 'reg_mun_gen_cap_re_density'
class Meta:
proxy = True
@property
def gen_cap_re_density(self):
return round(self.gen_cap_re / self.mundata.area, 2)
@property
def gen_cap_re_density_region(self):
return round(self.gen_cap_re_region / self.area_region, 2)
class RegMunGenCountWindDensity(RegMunPopDensity):
name = 'reg_mun_gen_count_wind_density'
class Meta:
proxy = True
@property
def gen_count_wind_density(self):
return round(self.mundata.gen_count_wind / self.mundata.area, 2)
@property
def gen_count_wind_density_region(self):
result = MunData.objects.aggregate(Sum('gen_count_wind'))['gen_count_wind__sum']
return round(result / self.area_region, 2)
class RegMunDemElEnergyPerCapita(RegMunDemElEnergy, RegMunPop):
name = 'reg_mun_dem_el_energy_per_capita'
class Meta:
proxy = True
@property
def dem_el_energy_per_capita(self):
return round(self.dem_el_energy * 1e6 / self.mundata.pop_2017)
@property
def dem_el_energy_per_capita_region(self):
return round(self.dem_el_energy_region * 1e6 / self.pop_region)
class RegMunDemThEnergy(RegMun):
name = 'reg_mun_dem_th_energy'
class Meta:
proxy = True
@property
def dem_th_energy(self):
return round((self.mundata.dem_th_energy_hh +
self.mundata.dem_th_energy_rca) / 1e3)
@property
def dem_th_energy_region(self):
result = MunData.objects.aggregate(Sum('dem_th_energy_hh'))['dem_th_energy_hh__sum'] + \
MunData.objects.aggregate(Sum('dem_th_energy_rca'))['dem_th_energy_rca__sum']
return round(result / 1e3)
class RegMunDemThEnergyPerCapita(RegMunDemThEnergy, RegMunPopDensity):
name = 'reg_mun_dem_th_energy_per_capita'
class Meta:
proxy = True
@property
def dem_th_energy_per_capita(self):
return round(self.dem_th_energy * 1e6 / self.mundata.pop_2017)
@property
def dem_th_energy_per_capita_region(self):
return round(self.dem_th_energy_region * 1e6 / self.pop_region)
# TODO: Add docstrings for models below
class RegWaterProtArea(LayerModel):
name = 'reg_water_prot_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
schutzzone = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
amtsblatt = models.CharField(max_length=254, null=True)
class RegBirdProtArea(LayerModel):
name = 'reg_bird_prot_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegBirdProtAreaB200(LayerModel):
name = 'reg_bird_prot_area_b200'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegNatureProtArea(LayerModel):
name = 'reg_nature_prot_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
schutzzone = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegLandscProtAreaParts(LayerModel):
name = 'reg_landsc_prot_area_parts'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
class RegResidArea(LayerModel):
name = 'reg_resid_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegResidAreaB500(LayerModel):
name = 'reg_resid_area_b500'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegPrioAreaFloodProt(LayerModel):
name = 'reg_prio_area_flood_prot'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bemerkunge = models.CharField(max_length=254, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
bezeich_3 = models.CharField(max_length=254, null=True)
class RegSurfaceWater(LayerModel):
"""Surface water
Oberflächengewässer (Fließgewässer 1. Ordnung, stehende Gewässer > 1 ha).
"""
name = 'reg_surface_water'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegPrioAreaCult(LayerModel):
name = 'reg_prio_area_cult'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegForest(LayerModel):
name = 'reg_forest'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegFFHProtArea(LayerModel):
name = 'reg_ffh_prot_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegResidAreaB1000(LayerModel):
name = 'reg_resid_area_b1000'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegPrioAreaWEC(LayerModel):
name = 'reg_prio_area_wec'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
bezeich_3 = models.CharField(max_length=254, null=True)
class GenWEC(LayerModel):
name = 'gen_wec'
geom = geomodels.MultiPointField(srid=3035, null=True)
class GenPVGround(LayerModel):
name = 'gen_pv_ground'
geom = geomodels.MultiPointField(srid=3035, null=True)
class RegDeadZoneHard(LayerModel):
name = 'reg_dead_zone_hard'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegDeadZoneSoft(LayerModel):
name = 'reg_dead_zone_soft'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
# TODO: New layers below -> insert data into DB!
class RegFFHProtAreaB(LayerModel):
name = 'reg_ffh_prot_area_b'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegLandscProtArea(LayerModel):
name = 'reg_landsc_prot_area'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegNaturePark(LayerModel):
name = 'reg_nature_park'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegBioReserve(LayerModel):
name = 'reg_bio_reserve'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
schutzzone = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegRetentAreaEcosys(LayerModel):
name = 'reg_retent_area_ecosys'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegPrioAreaNature(LayerModel):
name = 'reg_prio_area_nature'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegNatureMonum(LayerModel):
name = 'reg_nature_monum'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
gebietsnam = models.CharField(max_length=254, null=True)
gebietsnum = models.CharField(max_length=254, null=True)
rechtsgrun = models.CharField(max_length=254, null=True)
erfassungs = models.CharField(max_length=254, null=True)
info_konta = models.CharField(max_length=254, null=True)
class RegPrioAreaWater(LayerModel):
name = 'reg_prio_area_water'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegPrioAreaAgri(LayerModel):
name = 'reg_prio_area_agri'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegRetentAreaAgri(LayerModel):
name = 'reg_retent_area_agri'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegPrioAreaRes(LayerModel):
name = 'reg_prio_area_res'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
bezeich_2 = models.CharField(max_length=254, null=True)
class RegInfrasRailway(LayerModel):
name = 'reg_infras_railway'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegInfrasRoad(LayerModel):
name = 'reg_infras_road'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegInfrasHvgrid(LayerModel):
name = 'reg_infras_hvgrid'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
class RegInfrasAviation(LayerModel):
name = 'reg_infras_aviation'
geom = geomodels.MultiPolygonField(srid=3035, null=True)
##########################
# Layer models (results) #
##########################
class ResultLayerModel(RegMun):
"""This model is a dummy proxy model for displaying layer results
Notes
-----
It bases the municipalities' model :class:`stemp_abw.models.RegMun` which
is required (geom, names) for all result layers. The result data column
cannot be defined using property decorator as the results are stored in
:class:`stemp_abw.results.results.Results` which is connected to a
session and not accessible from models. Instead, the result column is
dynamically added in the serial view
:class:`stemp_abw.views.serial_views.GeoJSONResultLayerData`.
"""
name = None
class Meta:
proxy = True
@classmethod
def name_init(cls, name):
"""Class method to set model name property which is needed to match the
layer configuration (config/layers_results.cfg) and control (associated
layer switch in GUI).
Parameters
----------
name : :obj:`str`
Model name as used in config/layers_results.cfg
"""
cls.name = name
return cls
# TODO: Alter extended classes to result classes
class RegMunEnergyReElDemShareResult(RegMun):
name = 'reg_mun_energy_re_el_dem_share_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunGenEnergyReResult(RegMun):
name = 'reg_mun_gen_energy_re_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunGenEnergyReDensityResult(RegMun):
name = 'reg_mun_gen_energy_re_density_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunGenCapReResult(RegMun):
name = 'reg_mun_gen_cap_re_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunGenCapReDensityResult(RegMun):
name = 'reg_mun_gen_cap_re_density_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunGenCountWindDensityResult(RegMun):
name = 'reg_mun_gen_count_wind_density_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunDemElEnergyResult(RegMun):
name = 'reg_mun_dem_el_energy_result'
class Meta:
proxy = True
# TODO: Alter extended class to result class
class RegMunDemElEnergyPerCapitaResult(RegMun):
name = 'reg_mun_dem_el_energy_per_capita_result'
class Meta:
proxy = True
################################
# Layer models (results DELTA) #
################################
# TODO: This is a test delta layer
class RegMunEnergyReElDemShareDeltaResult(RegMun):
name = 'reg_mun_energy_re_el_dem_share_result_delta'
class Meta:
proxy = True
@property
def energy_re_el_dem_share_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunGenEnergyReDeltaResult(RegMun):
name = 'reg_mun_gen_energy_re_result_delta'
class Meta:
proxy = True
@property
def gen_energy_re_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunGenEnergyReDensityDeltaResult(RegMun):
name = 'reg_mun_gen_energy_re_density_result_delta'
class Meta:
proxy = True
@property
def gen_energy_re_density_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunGenCapReDeltaResult(RegMun):
name = 'reg_mun_gen_cap_re_result_delta'
class Meta:
proxy = True
@property
def gen_cap_re_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunGenCapReDensityDeltaResult(RegMun):
name = 'reg_mun_gen_cap_re_density_result_delta'
class Meta:
proxy = True
@property
def gen_cap_re_density_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunGenCountWindDensityDeltaResult(RegMun):
name = 'reg_mun_gen_count_wind_density_result_delta'
class Meta:
proxy = True
@property
def gen_count_wind_density_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunDemElEnergyDeltaResult(RegMun):
name = 'reg_mun_dem_el_energy_result_delta'
class Meta:
proxy = True
@property
def dem_el_energy_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
# TODO: This is a test delta layer
class RegMunDemElEnergyPerCapitaDeltaResult(RegMun):
name = 'reg_mun_dem_el_energy_per_capita_result_delta'
class Meta:
proxy = True
@property
def dem_el_energy_per_capita_result_delta(self):
return str(random.randrange(-100, 100, 1)) + '%'
###############
# Data models #
###############
# The following tables contain initial data only, data that result from
# adjustments in the tool are not saved to these tables.
class MunData(models.Model):
"""Statistical data of municipalities (status quo)
Attributes
----------
ags :
Municipality key (Amtlicher Gemeindeschlüssel),
refers to :class:`stemp_abw.models.RegMun`
area :
Total area in km^2
pop_2011 :
Population (2011) according to Zensus
pop_2017 :
Population (2017) according to GV-ISys
pop_2030 :
Population (2030) forecast according to MLV Sachsen-Anhalt
pop_2050 :
Population (2050), linearly extrapolated using 2017 and 2030
total_living_space :
Total living space (Wohnfläche) in m^2
gen_count_wind :
Count of wind turbines
gen_count_pv_roof_small :
Count of small (<=30 kVA) roof-mounted PV systems
gen_count_pv_roof_large :
Count of large (>30 kVA, <=300 kVA) roof-mounted PV systems
gen_count_pv_ground :
Count of ground-mounted PV systems (>300 kVA)
gen_count_hydro :
Count of run-of-river systems
gen_count_bio :
Count of biogas/biomass systems
gen_count_conventional_large :
Count of large (>=10 MW) conventional plants in MW
gen_count_conventional_small :
Count of small (<10 MW) conventional plants in MW.
Simplified assumption: 1 plant per municipality
gen_count_sewage_landfill_gas :
Count of sewage/landfill gas systems
gen_count_storage :
Count of storages
gen_capacity_wind :
Total nominal power of wind turbines in MVA
gen_capacity_pv_roof_small :
Total nominal power of small roof-mounted PV systems in MW
gen_capacity_pv_roof_large :
Total nominal power of large roof-mounted PV systems in MW
gen_capacity_pv_ground :
Total nominal power of ground-mounted PV systems in MW
gen_capacity_hydro :
Total nominal power of run-of-river systems in MW
gen_capacity_bio :
Total nominal power of biogas/biomass systems in MW
gen_capacity_conventional_large :
Total nominal power of large (>=10 MW) conventional plants in MW
gen_capacity_conventional_small :
Total nominal power of small (<10 MW) conventional plants in MW
gen_capacity_sewage_landfill_gas :
Total nominal power of sewage/landfill gas systems in MW
gen_capacity_storage :
Total storage capacity of storages in MWh
gen_el_energy_wind :
Annual el. energy fed in by wind turbines in MWh
gen_el_energy_pv_roof :
Annual el. energy fed in by roof-mounted PV systems in MWh
gen_el_energy_pv_ground:
Annual el. energy fed in by ground-mounted PV systems in MWh
gen_el_energy_hydro :
Annual el. energy fed in by run-of-river systems in MWh
gen_el_energy_bio :
Annual el. energy fed in by biomass/biogas systems incl. sewage and
landfill gas in MWh
gen_el_energy_conventional :
Annual el. energy fed in by conventional power plants in MWh (large
>=10 MW and small <10 MW).
dem_el_peak_load_hh :
El. peak demand of households in MW
dem_el_peak_load_rca :
El. peak demand of retail, commercial and agricultural sector (GHD)
in MW
dem_el_peak_load_ind :
El. peak demand of industry in MW
dem_el_energy_hh :
Annual el. energy consumed by households in MWh
dem_el_energy_rca :
Annual el. energy consumed by retail, commercial and agricultural
sector (GHD) in MWh
dem_el_energy_ind :
Annual el. energy consumed by industry in MWh
dem_th_peak_load_hh :
Heat peak demand of households in MW
dem_th_peak_load_rca :
Heat peak demand of retail, commercial and agricultural sector (GHD)
in MW
dem_th_peak_load_ind :
Heat peak demand of industry in MW
dem_th_energy_hh :
Annual heat consumed by households in MWh
dem_th_energy_hh_efh :
Annual heat consumed by single-family households (Einfamilienhäuser)
in MWh
dem_th_energy_hh_mfh :
Annual heat consumed by multi-family households (Mehrfamilienhäuser)
in MWh
dem_th_energy_hh_efh_spec :
Annual heat consumed by single-family households (Einfamilienhäuser),
area-specific in kWh/m^2
dem_th_energy_hh_mfh_spec :
Annual heat consumed by multi-family households (Mehrfamilienhäuser),
area-specific in kWh/m^2
dem_th_energy_rca :
Annual heat consumed by retail, commercial and agricultural sector
(GHD) in MWh
dem_th_energy_ind :
Annual heat consumed by industry in MWh
dem_th_energy_hh_per_capita :
Annual heat demand of households per capita in MWh
dem_th_energy_total_per_capita :
Annual heat demand of households, retail, commercial and agricultural
sector per capita in MWh
reg_prio_area_wec_area :
Area sum of priority areas (parts) in ha
reg_prio_area_wec_count :
Count of priority area (parts)
"""
ags = models.OneToOneField(RegMun, primary_key=True, on_delete=models.DO_NOTHING)
area = models.FloatField(null=True)
pop_2011 = models.IntegerField(null=True)
pop_2017 = models.IntegerField(null=True)
pop_2030 = models.IntegerField(null=True)
pop_2050 = models.IntegerField(null=True)
total_living_space = models.FloatField(null=True)
gen_count_wind = models.FloatField(null=True)
gen_count_pv_roof_small = models.FloatField(null=True)
gen_count_pv_roof_large = models.FloatField(null=True)
gen_count_pv_ground = models.FloatField(null=True)
gen_count_hydro = models.FloatField(null=True)
gen_count_bio = models.FloatField(null=True)
gen_count_conventional_large = models.FloatField(null=True)
gen_count_conventional_small = models.FloatField(null=True)
gen_count_sewage_landfill_gas = models.FloatField(null=True)
gen_count_storage = models.FloatField(null=True)
gen_capacity_wind = models.FloatField(null=True)
gen_capacity_pv_roof_small = models.FloatField(null=True)
gen_capacity_pv_roof_large = models.FloatField(null=True)
gen_capacity_pv_ground = models.FloatField(null=True)
gen_capacity_hydro = models.FloatField(null=True)
gen_capacity_bio = models.FloatField(null=True)
gen_capacity_conventional_large = models.FloatField(null=True)
gen_capacity_conventional_small = models.FloatField(null=True)
gen_capacity_sewage_landfill_gas = models.FloatField(null=True)
gen_capacity_storage = models.FloatField(null=True)
gen_el_energy_wind = models.FloatField(null=True)
gen_el_energy_pv_roof = models.FloatField(null=True)
gen_el_energy_pv_ground = models.FloatField(null=True)
gen_el_energy_hydro = models.FloatField(null=True)
gen_el_energy_bio = models.FloatField(null=True)
gen_el_energy_conventional = models.FloatField(null=True)
dem_el_peak_load_hh = models.FloatField(null=True)
dem_el_peak_load_rca = models.FloatField(null=True)
dem_el_peak_load_ind = models.FloatField(null=True)
dem_el_energy_hh = models.FloatField(null=True)
dem_el_energy_rca = models.FloatField(null=True)
dem_el_energy_ind = models.FloatField(null=True)
dem_th_peak_load_hh = models.FloatField(null=True)
dem_th_peak_load_rca = models.FloatField(null=True)
dem_th_peak_load_ind = models.FloatField(null=True)
dem_th_energy_hh = models.FloatField(null=True)
dem_th_energy_hh_efh = models.FloatField(null=True)
dem_th_energy_hh_mfh = models.FloatField(null=True)
dem_th_energy_hh_efh_spec = models.FloatField(null=True)
dem_th_energy_hh_mfh_spec = models.FloatField(null=True)
dem_th_energy_rca = models.FloatField(null=True)
dem_th_energy_ind = models.FloatField(null=True)
dem_th_energy_hh_per_capita = models.FloatField(null=True)
dem_th_energy_total_per_capita = models.FloatField(null=True)
reg_prio_area_wec_area = models.FloatField(null=True)
reg_prio_area_wec_count = models.IntegerField(null=True)
class FeedinTs(models.Model):
"""Feedin timeseries (hourly, partly normalized - see columns)
Attributes
----------
id :
DB id
timestamp :
timestamp
ags :
Municipality key (Amtlicher Gemeindeschlüssel),
refers to :class:`stemp_abw.models.RegMun`
pv_ground :
Photovoltaics (ground-mounted systems)
normalized (relative values)
pv_roof :
Photovoltaics (roof-mounted systems)
normalized (relative values)
hydro :
Run-of-river plants
normalized (relative values)
wind_sq :
Wind turbines (status quo)
normalized (relative values)
wind_fs :
Wind turbines (future scenarios)
normalized (relative values)
bio :
Biogas/biomass plants (incl. landfill and sewage)
normalized (relative values)
conventional :
Conventional plants (>=10 MW: power-led, <10 MW: heat-led)
NOT normalized (absolute values)
Notes
-----
Timeseries are stored per timestep and ags -> one dataset is uniquely
identified by timestamp and municipality's ags.
"""
id = models.BigAutoField(primary_key=True)
timestamp = models.DateTimeField(db_index=True)
ags = models.ForeignKey(RegMun, on_delete=models.DO_NOTHING)
pv_ground = models.FloatField(blank=True, null=True)
pv_roof = models.FloatField(blank=True, null=True)
hydro = models.FloatField(blank=True, null=True)
wind_sq = models.FloatField(blank=True, null=True)
wind_fs = models.FloatField(blank=True, null=True)
bio = models.FloatField(blank=True, null=True)
conventional = models.FloatField(blank=True, null=True)
class Powerplant(models.Model):
"""Power plants (status quo)
Attributes
----------
id :
DB id
ags :
Municipality key (Amtlicher Gemeindeschlüssel),
refers to :class:`stemp_abw.models.RegMun`
capacity :
Nominal power in MW
chp :
Indicates if plant is of type CHP (combined heat and power)
com_month :
Month of commissioning
com_year :
Year of commissioning
comment :
Comment
decom_month :
Month of decommissioning
decom_year :
Year of decommissioning
efficiency :
Efficiency
energy_source_level_1 :
Indicates if renewable or conventional
energy_source_level_2 :
Indicates energy source
energy_source_level_3 :
More specific energy source
geometry : Geometry
SRID: EPSG:4326 (WGS84)
technology :
Technology