Coverage for gws-app/gws/plugin/alkis/data/geo_info_dok/extract_props.py: 0%

40 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Print the property classes and the ``PROPS`` dict for ``types.py`` from the ``gid6`` schema.""" 

2 

3import gid6 as gid 

4 

5type_map = { 

6 'CharacterString': 'str', 

7 'Boolean': 'bool', 

8 'Integer': 'int', 

9 'Length': 'int', 

10 'Area': 'float', 

11 'Volume': 'float', 

12 'DateTime': 'str', 

13 'Date': 'str', 

14} 

15 

16md = gid.METADATA 

17 

18all_titles = {} 

19 

20def get_props(topics): 

21 """Collect property declarations from the object types of the given categories. 

22 

23 Only attributes with a basic or code list type, and with the same type 

24 and title in all object types, are kept. Their titles are added to 

25 ``all_titles``. 

26 

27 Args: 

28 topics: Category key parts. Object types whose key contains any of them are used. 

29 

30 Returns: 

31 A sorted list of declaration lines, e.g. `` name: str``. 

32 """ 

33 

34 ptypes = {} 

35 titles = {} 

36 

37 for v in md.values(): 

38 if v['kind'] == 'object' and any(t in v['key'] for t in topics): 

39 for a in v['attributes']: 

40 n = a['name'] 

41 t = a['type'] 

42 

43 if t in md and md[t].get('kind') == 'enum': 

44 t = 'EnumPair' 

45 elif t in type_map: 

46 t = type_map[t] 

47 else: 

48 # ignore object types for now 

49 # print('ignored type', n, t) 

50 t = '' 

51 

52 if t and a['list'] == 1: 

53 t = 'list[' + t + ']' 

54 

55 ptypes.setdefault(n, []).append(t) 

56 titles.setdefault(n, []).append(a['title']) 

57 

58 decls = [] 

59 

60 for n in ptypes: 

61 ptype = set(ptypes[n]) 

62 title = set(titles[n]) 

63 

64 if len(ptype) > 1 or len(title) > 1 or '' in ptype or '' in title: 

65 # print('mixed key', k, ptype, title) 

66 continue 

67 

68 all_titles[n] = title.pop() 

69 decls.append(f' {n}: {ptype.pop()}') 

70 

71 return sorted(decls) 

72 

73 

74py = get_props([ 

75 'gebaeude/angaben_zum_gebaeude', 

76]) 

77 

78print('\n\nclass GebaeudeProps(Object):') 

79print('\n'.join(py)) 

80 

81py = get_props([ 

82 'tatsaechliche_nutzung', 

83 'gesetzliche_festlegungen_gebietseinheiten_kataloge/bodenschaetzung_bewertung', 

84 'gesetzliche_festlegungen_gebietseinheiten_kataloge/oeffentlich_rechtliche_und_sonstige_festlegungen', 

85]) 

86 

87print('\n\nclass PartProps(Object):') 

88print('\n'.join(py)) 

89 

90print('\n\nPROPS = {') 

91for k in sorted(all_titles): 

92 print(f' {k!r}: {all_titles[k]!r},') 

93print('}')