11from ipyautoui .automapschema import pydantic_model_from_json_schema
22from ipyautoui .automapschema import pydantic_model_file_from_json_schema
33from ipyautoui .custom .edittsv import EditTsvWithDiff
4+ from ipyautoui .custom .edittsv_with_diff_and_key_mapping import EditTsvWithDiffAndKeyMapping
45import pathlib
5- import numpy as np
66
77
88json_schema = {
413413from IPython .display import display
414414
415415class Test (BaseModel ):
416+ a_int : int = Field (
417+ 1 ,
418+ title = "A Int" ,
419+ )
420+
416421 a_string : str = Field (
417422 "empty" ,
418423 title = "A String" ,
@@ -436,15 +441,265 @@ class TestArray(RootModel[List[Test]]):
436441edit_tsv_w_diff = EditTsvWithDiff (
437442 model = TestArray ,
438443 transposed = False ,
439- primary_key_name = "a_string " ,
444+ primary_key_name = "a_int " ,
440445 header_depth = 1 ,
441446 exclude_metadata = True ,
442- value = [{"a_string" : "hm" , "a_list" : "['Hello', 'Hey']" }]
447+ value = [{"a_int" : 1 , " a_string" : "hm" , "a_list" : "['Hello', 'Hey']" }]
443448)
444449display (edit_tsv_w_diff )
445450
446- display (edit_tsv_w_diff .value )
451+ print (edit_tsv_w_diff .changes )
452+ print (f'\n \n \n Value:{ edit_tsv_w_diff .value } ' )
447453
448454eval (edit_tsv_w_diff .value [0 ]["a_list" ])
449455
456+ # +
457+ """Issue with Date Validation (Project Building Area in Digital Schedules)"""
458+ from __future__ import annotations
459+
460+ from enum import Enum , IntEnum
461+ from typing import List , Optional
462+
463+ from pydantic import BaseModel , Field , RootModel
464+
465+
466+ class Abbreviation (Enum ):
467+ BLDG = 'BLDG'
468+
469+
470+ class TargetYear (IntEnum ):
471+ INTEGER_2025 = 2025
472+ INTEGER_2026 = 2026
473+ INTEGER_2027 = 2027
474+ INTEGER_2028 = 2028
475+ INTEGER_2029 = 2029
476+ INTEGER_2030 = 2030
477+ INTEGER_2031 = 2031
478+ INTEGER_2032 = 2032
479+ INTEGER_2033 = 2033
480+ INTEGER_2034 = 2034
481+ INTEGER_2035 = 2035
482+ INTEGER_2036 = 2036
483+ INTEGER_2037 = 2037
484+ INTEGER_2038 = 2038
485+ INTEGER_2039 = 2039
486+ INTEGER_2040 = 2040
487+ INTEGER_2050 = 2050
488+
489+
490+ class ProjectBuildingAreaItem (BaseModel ):
491+ Abbreviation_1 : Optional [Abbreviation ] = Field (
492+ 'BLDG' ,
493+ alias = 'Abbreviation' ,
494+ description = 'equipment type abbreviation, alphabetic characters only, variable length, between 2 and 6 characters' ,
495+ title = 'Abbreviation' ,
496+ )
497+ TypeReference : Optional [int ] = Field (
498+ 1 ,
499+ description = 'equipment type reference, integer only. Refers to equipment type, there may be multiple instances of the same type' ,
500+ title = 'Type Reference' ,
501+ )
502+ TargetYear_1 : Optional [TargetYear ] = Field (
503+ None ,
504+ alias = 'TargetYear' ,
505+ description = 'Net Zero Carbon targets change annually. This defined what year the Benchmark Targets should be defined by.' ,
506+ title = 'Target Year' ,
507+ )
508+ Name : Optional [str ] = Field (
509+ None ,
510+ description = 'Optional. Add a building name as used in the project for easier identification.' ,
511+ title = 'Building Name' ,
512+ )
513+ Id : Optional [int ] = Field (None , description = '' , title = 'Id' )
514+
515+
516+ class ProjectBuildingArea (RootModel [List [ProjectBuildingAreaItem ]]):
517+ root : List [ProjectBuildingAreaItem ] = Field (..., title = 'ProjectBuildingArea' )
518+
519+ model = ProjectBuildingArea
520+
521+ pbas_edt = EditTsvWithDiffAndKeyMapping (
522+ model = model ,
523+ transposed = True ,
524+ primary_key_name = "a_int" ,
525+ header_depth = 1 ,
526+ exclude_metadata = True ,
527+ value = [{'Abbreviation' : 'BLDG' ,
528+ 'TypeReference' : 1 ,
529+ 'TargetYear' : 2025 ,
530+ 'Name' : 'Block A' },
531+ {'Abbreviation' : 'BLDG' ,
532+ 'TypeReference' : 3 ,
533+ 'TargetYear' : 2026 ,
534+ 'Name' : 'Block B' }]
535+ )
536+ display (pbas_edt )
537+ # +
538+ from __future__ import annotations
539+
540+ from datetime import date
541+ from enum import Enum
542+ from typing import List , Optional
543+
544+ from pydantic import BaseModel , Field , RootModel
545+
546+
547+ class EnergyEndUse (Enum ):
548+ HEATING = 'Heating'
549+ DOMESTIC_HOT_WATER = 'Domestic Hot Water'
550+ HEATING___DOMESTIC_HOT_WATER = 'Heating & Domestic Hot Water'
551+ COOLING = 'Cooling'
552+ AUXILIARY = 'Auxiliary'
553+ LIGHTING = 'Lighting'
554+ SMALL_POWER = 'Small Power'
555+ IT_SERVERS = 'IT/Servers'
556+ PV_GENERATION = 'PV Generation'
557+ LIFTS = 'Lifts'
558+ CATERING = 'Catering'
559+ OTHER = 'Other'
560+ UNKNOWN = 'Unknown'
561+
562+
563+ class EnergyEndUseTag (Enum ):
564+ HEATING = 'Heating'
565+ HEATING___DISTRIBUTION_LOSS = 'Heating - Distribution Loss'
566+ DOMESTIC_HOT_WATER = 'Domestic Hot Water'
567+ COOLING = 'Cooling'
568+ AUXILIARY = 'Auxiliary'
569+ LIGHTING = 'Lighting'
570+ LIGHTING___EXTERNAL = 'Lighting - External'
571+ SMALL_POWER = 'Small Power'
572+ IT_SERVERS = 'IT/Servers'
573+ PV_GENERATION = 'PV Generation'
574+ POOL = 'Pool'
575+ LIFTS = 'Lifts'
576+ CATERING = 'Catering'
577+ OTHER = 'Other'
578+ UNKNOWN = 'Unknown'
579+
580+
581+ class FuelType (Enum ):
582+ ELECTRICITY = 'Electricity'
583+ GAS___NG = 'Gas - NG'
584+ GAS___BIOGAS = 'Gas - Biogas'
585+ GAS___LPG = 'Gas - LPG'
586+ GAS___OTHER = 'Gas - Other'
587+ UNKNOWN = 'Unknown'
588+ UNSET = 'Unset'
589+
590+
591+ class OperationalEnergyAnalysisType (Enum ):
592+ PART_L = 'Part L'
593+ SCOTTISH_PART_L = 'Scottish Part L'
594+ TM54 = 'TM54'
595+ PASSIVHAUS = 'Passivhaus'
596+ CUSTOM = 'Custom'
597+
598+
599+ class PredictedEnergyUseItem (BaseModel ):
600+ InstanceReference : Optional [int ] = Field (
601+ 1 ,
602+ description = 'equipment instance reference, integer only. Refers to equipment instance.' ,
603+ title = 'Instance Reference' ,
604+ )
605+ BuildingID : Optional [str ] = Field (
606+ None ,
607+ description = 'A unique identifier within the project assigned to a building' ,
608+ title = 'Building ID' ,
609+ )
610+ AssessmentDate : Optional [date ] = Field (
611+ None ,
612+ description = 'Date on which the overall condition is assessed' ,
613+ title = 'Assessment Date' ,
614+ )
615+ Notes : Optional [str ] = Field (None , description = '' , title = 'Notes' )
616+ OperationalEnergyAnalysisType_1 : Optional [OperationalEnergyAnalysisType ] = Field (
617+ None ,
618+ alias = 'OperationalEnergyAnalysisType' ,
619+ description = 'defines the type of analysis' ,
620+ title = 'Operational Energy Analysis Type' ,
621+ )
622+ FuelType_1 : Optional [FuelType ] = Field (
623+ None , alias = 'FuelType' , description = '' , title = 'Fuel Type'
624+ )
625+ EnergyConsumption : Optional [float ] = Field (
626+ None ,
627+ description = 'Annual energy consumption requirement. NOTE: PV Generation should be a -ve value.' ,
628+ title = 'Energy Consumption' ,
629+ )
630+ EnergyEndUse_1 : Optional [EnergyEndUse ] = Field (
631+ None ,
632+ alias = 'EnergyEndUse' ,
633+ description = 'The end-use of the energy consumption within a building. Pick the most appropriate.' ,
634+ title = 'Energy End Use' ,
635+ )
636+ EnergyEndUseTags : Optional [List [EnergyEndUseTag ]] = Field (
637+ None ,
638+ description = 'Avoid where possible. Use only when the "Energy End Use" does not correctly describe usage (e.g. mostly DHW, but add a lighting tag to indicate some lights).' ,
639+ title = 'Energy End Use Tags' ,
640+ )
641+ TypeMark : Optional [str ] = Field (None , description = '' , title = 'Type Mark' )
642+ TypeSpecId : Optional [int ] = Field (None , description = '' , title = 'Type Spec Id' )
643+ Id : Optional [int ] = Field (None , description = '' , title = 'Id' )
644+
645+
646+ class PredictedEnergyUse (RootModel [List [PredictedEnergyUseItem ]]):
647+ root : List [PredictedEnergyUseItem ] = Field (..., title = 'PredictedEnergyUse' )
648+
649+
650+ # -
651+
652+
653+ """Date format null warning (Predicted Energy Use in Digital Schedules)"""
654+ value = [{'InstanceReference' : 1 ,
655+ 'BuildingID' : 'BLDG-1' ,
656+ 'AssessmentDate' : None ,
657+ 'Notes' : None ,
658+ 'OperationalEnergyAnalysisType' : 'Part L' ,
659+ 'FuelType' : 'Electricity' ,
660+ 'EnergyConsumption' : 50.0 ,
661+ 'EnergyEndUse' : 'Heating' ,
662+ 'EnergyEndUseTags' : [],
663+ 'TypeMark' : None },
664+ {'InstanceReference' : 2 ,
665+ 'BuildingID' : 'BLDG-1' ,
666+ 'AssessmentDate' : None ,
667+ 'Notes' : None ,
668+ 'OperationalEnergyAnalysisType' : 'Part L' ,
669+ 'FuelType' : 'Electricity' ,
670+ 'EnergyConsumption' : 25.0 ,
671+ 'EnergyEndUse' : 'Cooling' ,
672+ 'EnergyEndUseTags' : [],
673+ 'TypeMark' : None },
674+ {'InstanceReference' : 3 ,
675+ 'BuildingID' : 'BLDG-1' ,
676+ 'AssessmentDate' : None ,
677+ 'Notes' : None ,
678+ 'OperationalEnergyAnalysisType' : 'Part L' ,
679+ 'FuelType' : 'Electricity' ,
680+ 'EnergyConsumption' : - 30.0 ,
681+ 'EnergyEndUse' : 'PV Generation' ,
682+ 'EnergyEndUseTags' : [],
683+ 'TypeMark' : None },
684+ {'InstanceReference' : 4 ,
685+ 'BuildingID' : 'BLDG-3' ,
686+ 'AssessmentDate' : None ,
687+ 'Notes' : None ,
688+ 'OperationalEnergyAnalysisType' : 'TM54' ,
689+ 'FuelType' : 'Electricity' ,
690+ 'EnergyConsumption' : 200.0 ,
691+ 'EnergyEndUse' : 'Heating' ,
692+ 'EnergyEndUseTags' : [],
693+ 'TypeMark' : None }]
694+ peu_edt = EditTsvWithDiffAndKeyMapping (
695+ model = PredictedEnergyUse ,
696+ primary_key_name = ["" , "" ],
697+ header_depth = 1 ,
698+ exclude_metadata = True ,
699+ value = value
700+ )
701+ display (peu_edt )
702+
703+ peu_edt .model .model_fields ['root' ].annotation .__args__ [0 ].model_fields
704+
450705
0 commit comments