>>> import json
>>> f = open('t.json')
>>> j = json.load(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/json/__init__.py", line 293, in load
return loads(fp.read(),
File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
>>>
from collections import defaultdict
from pprint import pprint
<spoiler title="values">
d =[{'Ref_Key': '33ed0832-9697-11eb-8568-18c04d0357e4', 'DataVersion': 'AAABRgAAAAA=', 'DeletionMark': False,
'Parent_Key': 'a888a6c7-bb96-11ea-834d-f0795994df35', 'IsFolder': True, 'Code': 'СГ-000359',
'Description': '1.1. Затраты на приобретение прав на ЗУ ', 'ВидДеятельностиДляНалоговогоУчетаЗатрат': None,
'ВидРасходовНУ': None, 'РеквизитДопУпорядочивания': '12', 'Код_Добавленный': '', 'Синтека_projectId': '',
'Predefined': False, 'PredefinedDataName': '',
'Parent@navigationLinkUrl': "Catalog_СтатьиЗатрат(guid'33ed0832-9697-11eb-8568-18c04d0357e4')/Parent"},
{'Ref_Key': '33ed0834-9697-11eb-8568-18c04d0357e4', 'DataVersion': 'AAABSAAAAAA=', 'DeletionMark': False,
'Parent_Key': 'a888a6c7-bb96-11ea-834d-f0795994df35', 'IsFolder': True, 'Code': 'СГ-000361',
'Description': '1.5. Затраты на аренду ЗУ ', 'ВидДеятельностиДляНалоговогоУчетаЗатрат': None,
'ВидРасходовНУ': None, 'РеквизитДопУпорядочивания': '13', 'Код_Добавленный': '', 'Синтека_projectId': '',
'Predefined': False, 'PredefinedDataName': '',
'Parent@navigationLinkUrl': "Catalog_СтатьиЗатрат(guid'33ed0834-9697-11eb-8568-18c04d0357e4')/Parent"},
{'Ref_Key': '33ed0836-9697-11eb-8568-18c04d0357e4', 'DataVersion': 'AAABSgAAAAA=', 'DeletionMark': False,
'Parent_Key': 'a888a6c7-bb96-11ea-834d-f0795994df35', 'IsFolder': True, 'Code': 'СГ-000363',
'Description': '1.6. Затраты на изменение ВРИ.Проектирование', 'ВидДеятельностиДляНалоговогоУчетаЗатрат': None,
'ВидРасходовНУ': None, 'РеквизитДопУпорядочивания': '14', 'Код_Добавленный': '', 'Синтека_projectId': '',
'Predefined': False, 'PredefinedDataName': '',
'Parent@navigationLinkUrl': "Catalog_СтатьиЗатрат(guid'33ed0836-9697-11eb-8568-18c04d0357e4')/Parent"},
{'Ref_Key': '33ed0838-9697-11eb-8568-18c04d0357e4', 'DataVersion': 'AAABTAAAAAA=', 'DeletionMark': False,
'Parent_Key': 'a888a6c7-bb96-11ea-834d-f0795994df35', 'IsFolder': True, 'Code': 'СГ-000365',
'Description': '1.8. Прочие затраты на улучшения и содержание ЗУ',
'ВидДеятельностиДляНалоговогоУчетаЗатрат': None, 'ВидРасходовНУ': None, 'РеквизитДопУпорядочивания': '15',
'Код_Добавленный': '', 'Синтека_projectId': '', 'Predefined': False, 'PredefinedDataName': '',
'Parent@navigationLinkUrl': "Catalog_СтатьиЗатрат(guid'33ed0838-9697-11eb-8568-18c04d0357e4')/Parent"}]</spoiler>
tree = defaultdict(list)
for value in d:
tree[value['Parent_Key']].append(value)
pprint(tree)
SELECT [ФИО], 1 AS Line,
[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]
FROM
( SELECT [ФИО],
DAY([Событие]) AS [День],
FORMAT([Событие], 'HH:mm') AS [Время]
FROM [Проходная]
WHERE FORMAT([Событие], 'yyyy-MM') = @P) AS enDay
PIVOT ( MIN([Время])
FOR [День] IN ( [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])
) AS enPivot
UNION
SELECT [ФИО], 2,
[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]
FROM
( SELECT [ФИО],
DAY([Событие]) AS [День],
FORMAT([Событие], 'HH:mm') AS [Время]
FROM [Проходная]
WHERE FORMAT([Событие], 'yyyy-MM') = @P) AS enDay
PIVOT ( MAX([Время])
FOR [День] IN ( [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])
) AS enPivot
UNION
SELECT [ФИО], 3,
[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]
FROM
( SELECT [ФИО],
DAY([Событие]) AS [День],
FORMAT(MAX([Событие]) - MIN([Событие]), 'HH:mm') AS [Время]
FROM [Проходная]
WHERE FORMAT([Событие], 'yyyy-MM') = @P
GROUP BY [ФИО], DAY([Событие])) AS enDay
PIVOT ( MAX([Время])
FOR [День] IN ( [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])
) AS enPivot
ORDER BY 1, 2
SELECT DISTINCT FORMAT([Событие], 'yyyy-MM')
FROM [Проходная]
ORDER BY 1 DESC
SELECT FORMAT(MAX([Событие]), 'yyyy-MM')
FROM [Проходная]