-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnobil2osm.py
975 lines (735 loc) · 30.4 KB
/
nobil2osm.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
#!/usr/bin/env python3
# -*- coding: utf8
# nobil2osm
# Converts nobil api to osm format for import/update.
# Usage: nobil2.osm
# The generated OSM file is saved to 'nobil.osm'
# New capacity types etc will produce warnings to console.
# Contact info, authentication and payment info have been removed from code because apps and RFID are mostly used.
import json
import html
import sys
import re
import urllib.request
version = "1.1.1"
# Capacities codes in kW
capacities = {
'7': 3.6, # 3,6 kW . 230V 1-phase max 16A
'16': 6.3, # 230V 3-phase max 16A
'8': 7.4, # 7.4 kW - 230V 1-phase max 32A
'10': 11, # 11 kW - 400V 3-phase max 16A
'17': 13, # 230V 3-phase max 32A
'19': 20, # 20 KW - 500VDC max 50A
'11': 22, # 22 kW - 400 3-phase max 32A
'18': 25, # 230V 3-phase max 63A
'37': 30, # 30 kW DC
'12': 43, # 43 kW - 400 3-phase max 63A
'13': 50, # 50 kW - 500VDC max 100A
'20': 50, # Less then 100 kW + 43 kW - 500VDC max 200A + 400V 3-phase max 63A
'21': 50, # Less then 100 kW + 22 kW - 500VDC max 50A + 400V 3-phase max 32A
'28': 50, # 50 kW - 400VDC max 125A
'38': 62, # 62.5 kW DC
'29': 75, # 75 kW DC
'23': 100, # 100 kW - 500VDC max 200A
'22': 135, # 135 kW - 480 VDC max 270A
'24': 150, # 150 kW DC
'30': 225, # 225 kW DC
'31': 250, # 250 kW DC
'32': 200, # 200 kW DC
'33': 300, # 300 kW DC
'25': 350, # 350 kW DC
'26': 350, # 350 bar
'36': 400, # 400 kW DC
'39': 500, # 500 kW DC
'0': 0} # Unspecified
# Brand names for certain national or regional networks
# Part 1 of tuple is translated into part 2 name, to allow for translations.
network_list = [
# Norway
('Mer', 'Mer'),
('Eviny', 'Eviny'),
('Lyse', 'Lyse'),
('Charge365', 'Charge365'),
('Kople', 'Kople'),
('Ragde Charge', 'Ragde Charge'),
('Uno-X', 'Uno-X'),
('Uno X', 'Uno-X'),
# Sweden
('Bee', 'Bee'),
('E.ON', 'E.ON'),
('Vattenfall', 'InCharge'),
('Göteborg Energi', 'Göteborg Energi'),
('OKQ8', 'OKQ8'),
# International
('Tesla', 'Tesla'),
# ('Shell Recharge', 'Shell Recharge'),
('Community by Shell Recharge', 'Shell Recharge'),
('Recharge', 'Recharge'),
('Circle K', 'Circle K'),
('Circle-K', 'Circle K'),
('Fortum','Fortum'),
('Ionity', 'Ionity') ]
# Output message to console
def message (text):
sys.stderr.write(text)
sys.stderr.flush()
# Produce a tag for OSM file
def make_osm_line(key,value):
if value:
value = html.unescape(value)
encoded_value = html.escape(value).strip()
file.write (' <tag k="' + key + '" v="' + encoded_value + '" />\n')
# Return capacity/wattage of socket
def find_capacity(capacity_id):
if capacity_id in capacity:
return capacity[capacity_id]
else:
message('Unknown capacity_id: "%s"\n' % capacity_id)
return 0
# Main program
if __name__ == '__main__':
message ("\nnobil2osm\n")
# Load all charging stations from Nobil
if len(sys.argv) > 1 and ".json" in sys.argv[1]:
message ("Loading charging stations from '%s'...\n" % sys.argv[1])
file = open(sys.argv[1])
nobil_data = json.load(file)
file.close()
else:
message ("Loading charging stations from Nobil api...\n")
link = "https://nobil.no/api/server/datadump.php?apikey=54f7f3c569d6f583f7ae8294966ddb68&format=json"
request = urllib.request.Request(link)
file = urllib.request.urlopen(request)
nobil_data = json.load(file)
file.close()
file = open("nobil.json", "w")
json.dump(nobil_data, file, indent=2, ensure_ascii=False)
file.close()
message ("Saved %i charging stations to 'nobil.json'\n" % len(nobil_data['chargerstations']))
# Only output selected country, if any
if len(sys.argv) > 1 and any(sys.argv[1].upper() == country for country in ["NOR", "SWE", "FIN", "DNK", "ISL"]):
country = sys.argv[1].upper()
else:
country = ""
# Produce OSM file header
message ("Generating OSM file...\n")
if country:
filename = "nobil_" + country.lower() + ".osm"
else:
filename = "nobil.osm"
file = open(filename, "w")
file.write ('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write ('<osm version="0.6" generator="nobil2osm v%s" upload="false" download="never">\n' % version)
count = 0
network_count = {}
node_id = -1000
# Loop all charging stations and produce OSM tags
for station in nobil_data['chargerstations']:
if country and station['csmd']['Land_code'] != country:
continue
node_id -= 1
count += 1
position = eval(station['csmd']['Position'])
if position[0] > 90 or position[1] > 180:
message ("Unknown coordinate: %s\n" % str(position))
continue
file.write(' <node id="' + str(node_id) + '" lat="' + str(position[0]) + '" lon="' + str(position[1]) + '">\n')
# make_osm_line("amenity","charging_station") # Moved to end due to hydrogen
make_osm_line("ref:nobil",str(station['csmd']['id']))
make_osm_line("OCPI", station['csmd']['ocpidb_mapping_stasjon_id'])
# make_osm_line("source","nobil.no")
make_osm_line("OWNER", station['csmd']['Owned_by'])
make_osm_line("OPERATOR", station['csmd']['Operator'])
make_osm_line("ADDRESS",station['csmd']['Street'] + " " + station['csmd']['House_number'] + ", " +\
station['csmd']['Zipcode'] + " " + station['csmd']['City'])
municipality = station['csmd']['Municipality'].strip()
if municipality and station['csmd']['Land_code'] == "NOR":
municipality = municipality.title()
municipality = municipality.replace(" Og ", " og ").replace(" I ", " i ")
municipality = municipality.replace(" (Viken)", "").replace(" (Innlandet)", "").strip()
# make_osm_line("MUNICIPALITY_ID",station['csmd']['Municipality_ID'])
make_osm_line("MUNICIPALITY",municipality)
# make_osm_line("COUNTY_ID",station['csmd']['County_ID'])
make_osm_line("COUNTY",station['csmd']['County'])
make_osm_line("COUNTRY",station['csmd']['Land_code'])
make_osm_line("CREATED",station['csmd']['Created'][:10])
make_osm_line("UPDATED",station['csmd']['Updated'][:10])
# make_osm_line("CHARGING_POINTS",str(station['csmd']['Number_charging_points']))
# Produce description tag
make_osm_line("DESCRIPTION", station['csmd']['Description_of_location'])
make_osm_line("COMMENT", station['csmd']['User_comment'])
'''
# Removed the following section to simplify tagging
if station['csmd']['Description_of_location'] != '':
description = station['csmd']['Description_of_location']
if station['csmd']['User_comment'] != '':
if not(description[len(description)-1] in ['.','!','?']):
description = description + "."
description = description + " " + station['csmd']['User_comment']
else:
description = station['csmd']['User_comment']
description = " ".join(description.split())
make_osm_line("DESCRIPTION",description)
# Generate contact email tag
# make_osm_line("CONTACT",station['csmd']['Contact_info'])
reg = re.search(r'\b([a-zA-Z][a-zA-Z0-9_.+-]*@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)\b', station['csmd']['Contact_info'])
if reg:
make_osm_line("contact:email",reg.group(1).lower())
# Generate contact phone tag
reg = re.search(r'(\+?[0-9]{5,15})', station['csmd']['Contact_info'].replace("(","").replace(")","").replace("-","").replace(" ",""))
if reg:
phone = reg.group(1)
if phone[:2] == "00":
phone = "+" + phone[2:]
if phone[:3] == "+47" or phone[:3] == "+46" or phone[:3] == "+45" or phone[:3] == "+31":
if phone[3] == "0":
phone = phone[:3] + " " + phone[4:]
else:
phone = phone[:3] + " " + phone[3:]
elif phone[:4] == "+358":
if phone[4] == "0":
phone = "+358 " + phone[5:]
else:
phone = "+358 " + phone[4:]
if phone[:1] == "0":
phone = phone[1:]
if phone[0] != "+":
if station['csmd']['Land_code'] == "NOR":
phone = "+47 " + phone
elif station['csmd']['Land_code'] == "SWE":
phone = "+46 " + phone
elif station['csmd']['Land_code'] == "FIN":
phone = "+358 " + phone
elif station['csmd']['Land_code'] == "DAN":
phone = "+45 " + phone
if len(phone) < 10:
phone = phone[:4] + "0" + phone[4:]
if phone == "+481750809":
phone = "+46 481750809"
elif phone == "+045578300":
phone = "+46 45578300"
make_osm_line("contact:phone",phone)
# Generate contact website
reg = re.search(r'(^|\s)([htps/:]*[a-z0-9.-]+[.][a-z]{2,5}[a-z0-9.?=#&_/-]*)[,]*(\s|$)', station['csmd']['Contact_info'].lower())
if reg:
website = reg.group(2).lower()
website = website.replace("www.","")
if website[:4] != "http":
website = "http://" + website
if website != "http://e.on":
make_osm_line("contact:website", website)
'''
# Loop each extra information item
for key, info in station['attr']['st'].items():
if info is None:
continue
# Produce OSM tag for availability
if key == '2':
if (station['csmd']['User_comment']
and ("endast" in station['csmd']['User_comment'].lower() or "kun" in station['csmd']['User_comment'].lower())
and "tesla" in station['csmd']['User_comment'].lower()): # Tesla cars only
make_osm_line("access", "customers")
elif info['attrvalid'] == '1': # Public
make_osm_line("access", "yes")
elif info['attrvalid'] == '2': # Visitors
make_osm_line("access", "customers")
elif info['attrvalid'] == '3': # Employees
make_osm_line("access", "employees")
elif info['attrvalid'] == '4': # By appointment
make_osm_line("access", "permissive")
elif info['attrvalid'] == '5': # Residents
make_osm_line("access", "residents")
else:
message('Unknown availability id: "%s" - %s\n' % (info['attrvalid'], info['trans']))
# Produce OSM tag for location
elif key == '3':
make_osm_line("LOCATION",info['trans'])
# Produce OSM tag for parking fee
elif key == '7':
if info['trans'] == 'Yes':
make_osm_line("parking:fee", "yes")
elif info['trans'] == 'No':
make_osm_line("parking:fee", "no")
'''
# Produce OSM tag for reservable
elif key == '18':
if info['trans'] == 'Yes':
make_osm_line("reservation", "yes")
elif info['trans'] == 'No':
make_osm_line("reservation", "no")
# Produce OSM tag for opening hours
elif key == '24':
make_osm_line("opening_hours", "24/7")
# Produce OSM tag for time limit
elif key == '6':
if info['trans'] == 'Yes':
make_osm_line("TIME_LIMIT", "yes")
elif info['trans'] == 'No':
make_osm_line("TIME_LIMIT", "no")
'''
# Loop all connectors for station and fetch info
sockets = {
'schuko': 0,
'tesla_roadster': 0,
'cee_blue': 0,
'cee_red': 0,
'type1': 0,
'type2': 0,
'type2_combo': 0,
'chademo': 0,
'tesla_supercharger': 0
}
capacity = {
'schuko': 0,
'tesla_roadster': 0,
'cee_blue': 0,
'cee_red': 0,
'type1': 0,
'type2': 0,
'type2_combo': 0,
'chademo': 0,
'tesla_supercharger': 0
}
authentication = {
'open': False,
'standard_key': False,
'rfid': False,
'payment': False,
'cellular': False
}
payment = {
'cellular': False,
'visa': False,
'mastercard': False,
'charging_card': False,
'coin': False,
'subscription': False,
'cards': False
}
vehicle = {
'battery': False,
'plugin': False,
'van': False,
'bus': False,
'moped': False,
'bike': False,
'short': False,
'boat': False
}
hydrogen = False
biogas = False
evse = []
capacity_adjustment = 0
for connector in station['attr']['conn'].values():
if '4' in connector and connector['4'] is not None: # "Connector"
# Find capacity
if "5" in connector:
if connector['5']['attrvalid'] in capacities:
connector_capacity = capacities[ connector['5']['attrvalid'] ]
elif connector['5']['attrvalid'] in ['26', '27']: # Hydrogen
hydrogen = True
connector_capacity = 0
elif connector['5']['attrvalid'] in ['34', '35']: # Biogas (34: CBG - Compressed biogas, 35: LBG - Liquified biogas)
biogas = True
connector_capacity = 0
else:
connector_capacity = 0
message('Unexpected capacity: "%s" - %s\n' % (connector['5']['attrvalid'], connector['5']['trans']))
make_osm_line("FIXME", "Socket output (kW)")
else:
connector_capacity = 0
# Increase number of connectors by 1 and set capacity
if connector['4']['attrvalid'] == '14': # Schuko / Schucko CEE 7/4
sockets['schuko'] += 1
if '5' in connector:
capacity['schuko'] = max(capacity['schuko'], connector_capacity)
elif connector['4']['attrvalid'] == '29': # Tesla Connector Roadster
sockets['tesla_roadster'] += 1
if '5' in connector:
capacity['tesla_roadster'] = max(capacity['tesla_roadster'], connector_capacity)
elif connector['4']['attrvalid'] == '34': # Blue industrial 3-pin
sockets['cee_blue'] += 1
if '5' in connector:
capacity['cee_blue'] = max(capacity['cee_blue'], connector_capacity)
elif connector['4']['attrvalid'] == '35': # Blue industrial 4-pin
sockets['cee_blue'] += 1
if '5' in connector:
capacity['cee_blue'] = max(capacity['cee_blue'], connector_capacity)
elif connector['4']['attrvalid'] == '36': # Red industrial 5-pin
sockets['cee_red'] += 1
if '5' in connector:
capacity['cee_red'] = max(capacity['cee_red'], connector_capacity)
elif connector['4']['attrvalid'] == '31': # Type 1
sockets['type1'] += 1
if '5' in connector:
capacity['type1'] = max(capacity['type1'], connector_capacity)
elif connector['4']['attrvalid'] == '32': # Type 2
sockets['type2'] += 1
if '5' in connector:
capacity['type2'] = max(capacity['type2'], connector_capacity)
elif connector['4']['attrvalid'] == '60': # Type 1/Type 2
sockets['type1'] += 1
sockets['type2'] += 1
capacity_adjustment +=1
if '5' in connector:
capacity['type2'] = max(capacity['type2'], connector_capacity)
elif connector['4']['attrvalid'] == '50': # Type 2 + Chucko CEE 7/4
sockets['schuko'] += 1
sockets['type2'] += 1
capacity_adjustment +=1
capacity['schuko'] = max(capacity['schuko'],3.6)
if '5' in connector:
capacity['type2'] = max(capacity['type2'], connector_capacity)
elif connector['4']['attrvalid'] == '39': # CCS/Combo
sockets['type2_combo'] += 1
if '5' in connector:
capacity['type2_combo'] = max(capacity['type2_combo'], connector_capacity)
elif connector['4']['attrvalid'] == '41': # Combo + CHAdeMO
sockets['type2_combo'] += 1
sockets['chademo'] += 1
if '5' in connector:
capacity['type2_combo'] = max(capacity['type2_combo'], connector_capacity)
capacity['chademo'] = max(capacity['chademo'], connector_capacity)
elif connector['4']['attrvalid'] == '42': # CHAdeMO + Type 2
sockets['chademo'] += 1
sockets['type2'] += 1
capacity_adjustment += 1
if '5' in connector:
capacity['chademo'] = max(capacity['chademo'], connector_capacity)
elif connector['4']['attrvalid'] == '30': # CHAdeMO
sockets['chademo'] += 1
if '5' in connector:
capacity['chademo'] = max(capacity['chademo'], connector_capacity)
elif connector['4']['attrvalid'] == '40': # Tesla Connector
if connector_capacity < 50: # Probably Tesla destination charger
sockets['type2'] += 1
if '5' in connector:
capacity['type2'] = max(capacity['type2'], connector_capacity)
elif connector_capacity > 150: # It is a V3 station, which is CCS/Combo
sockets['type2_combo'] += 1
if '5' in connector:
capacity['type2_combo'] = max(capacity['type2_combo'], connector_capacity)
else:
sockets['tesla_supercharger'] += 1
if '5' in connector:
capacity['tesla_supercharger'] = max(capacity['tesla_supercharger'], connector_capacity)
elif connector['4']['attrvalid'] == '43': # CHAdeMO + Combo + AC-Type2
sockets['chademo'] += 1
sockets['type2_combo'] += 1
sockets['type2'] += 1
capacity_adjustment += 1
if '5' in connector:
if connector['5']['attrvalid'] == 21:
# Less then 100 kW + 22 kW - 500VDC max 50A + 400V 3-phase max 32A
capacity['chademo'] = max(capacity['chademo'], 50)
capacity['type2_combo'] = max(capacity['type2_combo'], 50)
capacity['type2'] = max(capacity['chademo'], 22)
elif connector['5']['attrvalid'] == 20:
# Less then 100 kW + 43 kW - 500VDC max 200A + 400V 3-phase max 63A
capacity['chademo'] = max(capacity['chademo'], 50)
capacity['type2_combo'] = max(capacity['type2_combo'], 50)
capacity['type2'] = max(capacity['chademo'], 43)
else:
capacity['chademo'] = max(capacity['chademo'], connector_capacity)
capacity['type2_combo'] = max(capacity['type2_combo'], connector_capacity)
elif connector['4']['attrvalid'] == '70': # Hydrogen
hydrogen = True
elif connector['4']['attrvalid'] in ['80', '81', '82']: # Biogas LBG, CBG
biogas = True
elif connector['4']['attrvalid'] != "0": # Unspecified
message('Unexpected connector: "%s" - %s\n' % (connector['4']['attrvalid'], connector['4']['trans']))
'''
# Removed the following section to simplify tagging
# Fetch accessibility / authentication info for connector
if '1' in connector:
if connector['1']['attrvalid'] == '1': # Open
authentication['open'] = True
elif connector['1']['attrvalid'] == '2': # Standard key
authentication['standard_key'] = True
elif connector['1']['attrvalid'] == '4': # RFID
authentication['rfid'] = True
elif connector['1']['attrvalid'] == '5': # Payment
authentication['payment'] = True
elif connector['1']['attrvalid'] == '6': # Cellular phone
authentication['cellular'] = True
elif connector['1']['attrvalid'] != '3': # Not Other
message('Unexpected accessibility: "%s" - %s\n' % (connector['1']['attrvalid'], connector['1']['trans']))
# Fetch payment info for connector
if '19' in connector:
if connector['19']['attrvalid'] == '1': # Cellular phone
payment['cellular'] = True
elif connector['19']['attrvalid'] == '2': # VISA
payment['visa'] = True
elif connector['19']['attrvalid'] == '3': # Mastervard and VISA
payment['visa'] = True
payment['mastercard'] = True
elif connector['19']['attrvalid'] == '21': # VISA, Mastercard and Charging card
payment['visa'] = True
payment['mastercard'] = True
payment['charging_card'] = True
elif connector['19']['attrvalid'] == '20': # Cellular phone and Charging card
payment['cellular'] = True
payment['charging_card'] = True
elif connector['19']['attrvalid'] == '7': # Subscription
payment['subscription'] = True
elif connector['19']['attrvalid'] == '8': # Coin
payment['token'] = True
elif connector['19']['attrvalid'] == '6': # Other cards
payment['cards'] = True
elif connector['19']['attrvalid'] == '9': # Miscellaneous cards
payment['cards'] = True
elif connector['19']['attrvalid'] != '10': # Not Miscellaneous
message('Unexpected payment method: "%s" - %s\n' % (connector['19']['attrvalid'], connector['19']['trans']))
'''
# Fetch vehicle type
if '17' in connector:
if connector['17']['attrvalid'] in ['1', '11', '15']: # All (battery only) vehicles + Rechargeable cars and vans
vehicle['battery'] = True
elif connector['17']['attrvalid'] == '2': # Short vehicles
vehicle['short'] = True
elif connector['17']['attrvalid'] == '3': # Two-wheel mopeds
vehicle['moped'] = True
elif connector['17']['attrvalid'] == '4': # Electrical bikes
vehicle['bike'] = True
elif connector['17']['attrvalid'] == '5': # Plug-in hybrid
vehicle['plugin'] = True
elif connector['17']['attrvalid'] in ['6', '10', '14']: # Van, truck and bus
vehicle['van'] = True
vehicle['bus'] = True
elif connector['17']['attrvalid'] == '13':
vehicle['bus'] = True
elif connector['17']['attrvalid'] == '20':
vehicle['boat'] = True
elif connector['17']['attrvalid'] == '22': # Rechargeable cars, vans and boats
vehicle['battery'] = True
vehicle['van'] = True
vehicle['boat'] = True
elif connector['17']['attrvalid'] in ['7','8','9']: # Hydrogen vehicle
hydrogen = True
elif connector['17']['attrvalid'] == '16': # Biogas vehicle
biogas = True
else:
message('Unexpected vehicle type: "%s" - %s\n' % (connector['17']['attrvalid'], connector['17']['trans']))
# Check for hydrogen and biogas
if '26' in connector and connector['26'] is not None:
if connector['26']['attrvalid'] == "2":
hydrogen == True
elif connector['26']['attrvalid'] == "3":
biogas == True
# Build list of EVSE ids
if '28' in connector and connector['28'] is not None:
evse.append(connector['28']['attrval'])
# Produce osm tags with number of sockets per connector type
for connector_type, number_of_sockets in sockets.items():
if number_of_sockets > 0:
make_osm_line("socket:" + connector_type, str(number_of_sockets))
# Produce osm tags with capacity per connector type
for connector_type, capacity_per_connector in capacity.items():
if capacity_per_connector > 0.0:
make_osm_line("socket:" + connector_type + ":output", str(capacity_per_connector) + " kW")
max_capacity = max(capacity.values())
# Estimate capacity and produce osm tag
est_capacity = max(sockets['chademo'], sockets['type2_combo']) + sum(sockets.values()) - sockets['chademo'] - sockets['type2_combo'] - capacity_adjustment
if est_capacity > 0:
make_osm_line("capacity", str(est_capacity))
# Output EVSE ids
if evse:
make_osm_line("EVSE", ", ".join(evse))
'''
# Removed the following section to simplify tagging
# Produce osm tags for authentication
if authentication['open']:
make_osm_line("authentication:none", "yes")
if authentication['standard_key']:
make_osm_line("authentication:key", "yes")
if authentication['rfid']:
make_osm_line("authentication:nfc", "yes")
if authentication['cellular']:
make_osm_line("authentication:app", "yes")
if authentication['payment']:
make_osm_line("authentication:payment", "yes")
# Produce osm tags for payment method
if payment['visa']:
make_osm_line("payment:visa", "yes")
if payment['mastercard']:
make_osm_line("payment:mastercard", "yes")
if payment['charging_card']:
make_osm_line("payment:contactless", "yes")
if payment['cellular']:
make_osm_line("payment:app", "yes")
if payment['subscription']:
make_osm_line("payment:subscription", "yes")
if payment['coin']:
make_osm_line("payment:token", "yes")
if payment['cards']:
make_osm_line("payment:cards", "yes")
if True in payment.values() or authentication['payment']:
make_osm_line("fee", "yes")
'''
# Produce osm access tags for some vehicle types
if vehicle['van']:
make_osm_line("hgv", "yes")
if vehicle['bus']:
make_osm_line("bus", "yes")
if vehicle['plugin']:
make_osm_line("hybrid_car", "yes")
if vehicle['moped']:
make_osm_line("moped", "yes")
if vehicle['bike']:
make_osm_line("bicycle", "yes")
if vehicle['boat']:
make_osm_line("boat", "yes")
# Fix name in the following sections
name = station['csmd']['name']
original_name = name
# Remove "fastcharger" etc from name. Fixme: Finnish equivalents
for delete_word in ['hurtiglader', 'hurtigladestasjon', 'semihurtiglader', 'semihurtigladestasjon', 'fastcharger',
'snabbladdare', 'snabbladdstation', 'snabbladdningsstation', 'snabbladdning', '(snabb)', 'semiladdare',
'lader', 'ladestasjon', 'ladestasjoner', 'laddstation', 'laddplats', 'laddpunkten', 'laddgata', 'laddgatan',
'destinationsladdning', 'destinationsladdare',
'superladestasjon', 'superladerstasjon', 'superlader', 'teslalader', 'roadster', 'SC', 'supercharger',
'ved', 'på', 'AS', 'AB', 'Vattenfall', 'Charge and Drive']:
reg = re.search(r'\b(%s)\b' % delete_word, name, flags=re.IGNORECASE|re.UNICODE)
if reg:
name = name.replace(reg.group(1), '')
# Insert network name at the start of station name (only for high capacity chargers)
brand = ""
operator = ""
owner = ""
for network in network_list:
if station['csmd']['Owned_by'] and network[0].lower() in station['csmd']['Owned_by'].lower() and "Lillehammer" not in station['csmd']['Owned_by']:
name = network[1] + " " + name.replace(network[0], "").replace(network[1], "").lstrip(", ").strip()
brand = network[1]
break
if brand == "Tesla" and max_capacity < 50:
brand = ""
if brand in network_count:
network_count[ brand ] += 1
elif brand:
network_count[ brand ] = 1
'''
# First remove any existing network name from station name
reg1 = re.search(r'\b(%s)\b' % network[0], name, flags=re.IGNORECASE|re.UNICODE)
if reg1:
name = name.replace(reg1.group(1), '')
# If network present in station name, operator name or contact then insert network name at start of station name
reg2 = re.search('(%s)' % network[0], station['csmd']['Owned_by'], flags=re.IGNORECASE|re.UNICODE)
reg3 = re.search('(%s)' % network[0], station['csmd']['Contact_info'], flags=re.IGNORECASE|re.UNICODE)
reg4 = re.search('(%s)' % network[0], station['csmd']['User_comment'], flags=re.IGNORECASE|re.UNICODE)
if network[1] != "":
reg5 = re.search('(%s)' % network[1], station['csmd']['Contact_info'], flags=re.IGNORECASE|re.UNICODE)
reg6 = re.search('(%s)' % network[1], station['csmd']['User_comment'], flags=re.IGNORECASE|re.UNICODE)
else:
reg5 = None
reg6 = None
if reg1 or reg2 or reg3 or reg4 or reg5 or reg6:
name = network[0].replace("\\", "") + " " + name.lstrip(", ")
brand = network[0].replace("\\", "")
break
'''
# Lowercase certain words; uppercase others (or a mix)
for case in ['p-plass', 'p-plats', 'p-hus', 'p-anlegg', 'garasje', 'parkering', 'parkeringsplass', 'bygg',
'gjesteparkering', 'gästparkering', 'ansattparkering', 'utomhusparkering', 'fellesparkering', 'pendlerparkering', 'utfartsparkering',
'hotel', 'hotell', 'turisthotell', 'camping', 'fjellstove', 'turisthytte', 'slott', 'gård',
'airport', 'flyplass', 'flygplats', 'lufthamn', 'terminal',
'jernbanestasjon', 'järnvägsstation', 'stasjon', 'station', 't-bane', 'tågstation',
'sentrum', 'centrum', 'torg', 'resecentrum', 'central', 'plass', 'allé', 'allè',
'storsenter', 'senter', 'kjøpesenter', 'köpcenter', 'köpcentrum', 'møbelsenter', 'shopping', 'handelspark', 'handelsområde',
'industriområde', 'næringspark', 'konferanse', 'konferens',
'rådhus', 'kommunehus', 'kommunhus',
'kirke', 'kyrkje', 'kultursenter', 'kulturhus', 'kino', 'teater', 'bibliotek', 'samfunnshus',
'stadion', 'fritidssenter', 'aktivitetssenter', 'idrettshall', 'flerbrukshall',
'omsorgssenter', 'omsorgsboliger', 'sykehus', 'sjukhus', 'helsetun', 'sykehjem', 'sjukeheim',
'skole', 'skule', 'barneskole', 'barneskule', 'ungdomsskole', 'ungdomsskule', 'vgs', 'gymnas', 'fagskole', 'fagskule',
'kulturskole', 'kulturskule', 'folkehøyskole', 'folkehøgskule', 'katedralskole', 'oppvekstsenter', 'barnehage', 'barnehave',
'kommune', 'fylkeskommune',
'borettslag', 'sameie', 'boligsameie',
'besøkende', 'ansatte', 'gjester', 'tjenestebiler',
'Amfi', 'Coop', 'Q-Park']:
reg = re.search(r'\b(%s)\b' % case, name, flags=re.IGNORECASE|re.UNICODE)
if reg:
name = name.replace(reg.group(1), case)
# Remove superfluous spaces
name = name.replace(" - "," ")
name = name.replace(" – "," ")
name = name.replace(" ,", ",")
name = name.strip(", ")
name = name.replace(" "," ")
name = name.strip(" ")
if name[0:6] != "eRoute" and len(name) > 1:
name = name[0].upper() + name[1:]
if brand == "Tesla":
name += " Supercharger" # Official Tesla station name
# Fixes for Kople partners
if station['csmd']['Owned_by'] and "Ishavskraft" in station['csmd']['Owned_by'] and "Kople" not in name:
brand = "Kople"
name = "Kople " + name
if "Ishavskraft" not in name and "Ishavsveien" not in name:
name = name.replace("Kople", "Kople Ishavsveien")
name = name.replace("Ishavskraft", "Ishavsveien")
name = name.replace("PWR UP", "Pwr Up")
name = name.replace("LAD OPP", "Lad Opp")
name = name.replace("ChargeUP", "ChargeUp")
for partner in ["Ishavsveien", "Pwr Up", "Lad Opp", "ChargeUp"]:
if " " + partner + " " in name:
brand = partner
operator = "Kople"
break
# Remove municipality name (for Norway only)
if station['csmd']['Land_code'] == "NOR":
# Remove for Kople
if "Kople" in name:
for case in [municipality + " kommune", station['csmd']['County'] + " fylkeskommune"]:
test_name = name[ : len(name) - len(case) ]
if test_name + case == name:
test_name = test_name.replace(" , ", " ").replace(" ", " ").strip()
if test_name != "Kople":
name = test_name
owner = case
elif case in name:
owner = case
else:
# Remove at the end
split_name = name.split()
network_length = len(brand.split())
if len(split_name) > network_length and split_name[-1] == municipality and ", " in name:
name = name.rstrip(split_name[-1])
name = name.strip(", ")
# Produce osm tags for name and network
if not brand and not operator and station['csmd']['Operator'] and station['csmd']['Operator'] != "-":
operator = station['csmd']['Operator']
if not brand and not owner and station['csmd']['Owned_by'] and station['csmd']['Owned_by'] != "-" and station['csmd']['Owned_by'] != operator:
owner = station['csmd']['Owned_by']
# if operator.endswith(" AS"):
# operator = operator[:-3]
# if owner.endswith(" AS"):
# owner = owner[:-3]
make_osm_line("name",name)
make_osm_line("brand", brand)
make_osm_line("operator", operator)
make_osm_line("owner", owner)
# if brand != "":
# make_osm_line("brand", brand)
# elif station['csmd']['Owned_by'] and station['csmd']['Owned_by'] not in ["-", "Tesla"]:
# make_osm_line("operator", station['csmd']['Owned_by'])
if name != original_name:
make_osm_line("NOBIL_NAME", original_name)
# Produce amnity station tag
if not hydrogen and not biogas or est_capacity > 0:
make_osm_line("amenity", "charging_station")
else:
make_osm_line("amenity", "fuel")
# Questionable data quality
# if hydrogen:
# make_osm_line("fuel:h70", "yes")
# if biogas:
# make_osm_line("fuel:biogas", "yes")
# Done with OSM station node
file.write(' </node>\n')
# Produce OSM file footer
file.write('</osm>\n')
file.close()
message("Networks:\n")
for network in sorted(network_count, key=network_count.get, reverse=True):
message("\t%-20s %5i\n" % (network, network_count[ network ]))
message ("Saved %i charging stations to '%s'\n\n" % (count, filename))