Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify geographic content using python API in LINUX #12

Open
frozznight opened this issue Mar 6, 2024 · 5 comments
Open

Modify geographic content using python API in LINUX #12

frozznight opened this issue Mar 6, 2024 · 5 comments

Comments

@frozznight
Copy link

frozznight commented Mar 6, 2024

I am using this tool to generate consumption profile (e.g. water, electricity) as input for my building energy model using EnergyPlus.
I am working in the LINUX environment.
I am trying to modify the day schedules, especially the holidays, according to my local holidays.
As far as I looked at the python bindings (API), I could not find how to realized the modifications.
Are there any examples modifying the geographical contents using python API?
Thanks.

@frozznight frozznight changed the title Modify geographic content using python API Modify geographic content using python API in LINUX Mar 6, 2024
@frozznight
Copy link
Author

I have tried a workaround by directly accessing the database.
Maybe it seems too intrusive.

import os,glob,uuid,pylpg,sqlite3
import pandas as pd

def main():
    pylpgDir = os.path.dirname(pylpg.__file__)
    dbFile = glob.glob(os.path.sep.join((pylpgDir,"LPG_*","profilegenerator.db3")))[0]
    lpgDB = sqlite3.connect(dbFile)

    #Inserting the geographic data, for example Belgium
    lpgDB.execute("\
        INSERT INTO tblGeographicLocations\
        (Name,Guid)\
        VALUES\
        ('(Belgium) Brussels','{}')\
    ;".format(getUUID()))

    #The sqlite database is created using older version, therefore we have to query again to get the location ID
    #Otherwise, the sqlite insert command can accept RETURNING clause
    brusselID = pd.read_sql_query("\
        SELECT ID\
        FROM tblGeographicLocations\
        WHERE Name LIKE '%%Brussels%%'\
    ;",lpgDB)["ID"].values[0]

    #Example of holidays in Belgium
    holidayName = [
        "(Belgium) Easter Monday 2024",
        "(Belgium) Labour Day 2024",
        "(Belgium) Ascension Day 2024",
        "(Belgium) Whit Monday 2024",
        "(Belgium) Assumption Day 2024",
        "(Belgium) All Saints’ Day 2024",
        "(Belgium) Armistice Day 2024"
    ]
    holidayDates = [
        "1 April 2024 00:00:00",
        "1 May 2024 00:00:00",
        "9 May 2024 00:00:00",
        "20 May 2024 00:00:00",
        "15 August 2024 00:00:00",
        "1 November 2024 00:00:00",
        "11 November 2024 00:00:00"
    ]
    
    beDF = pd.DataFrame(
        data = {
            "holidayName" : holidayName,
            "holidayDates" : holidayDates
        }
    )
    beDF["holidayDatetime"] = pd.to_datetime(beDF["holidayDates"])

    #Inserting holiday dates to the database
    for iRow in beDF.index:
        holidayName = beDF.iloc[iRow]["holidayName"] 
        #The description may be rewritten otherwise
        holidayDesc = holidayName.replace("(Belgium) ","")
        holidayDate = beDF.iloc[iRow]["holidayDatetime"]
        guid = getUUID()
        lpgDB.execute("\
            INSERT INTO tblHolidays\
            (Name,Description,Guid)\
            VALUES\
            ('{}','{}','{}')\
        ;".format(holidayName,holidayDesc,guid))
        holidayID = pd.read_sql_query("\
            SELECT ID\
            FROM tblHolidays\
            WHERE Guid = '{}'\
        ;".format(guid),lpgDB)["ID"].values[0]
        guid = getUUID()
        lpgDB.execute("\
            INSERT INTO tblHolidayDates\
            (HolidayID,DateAndTime,Guid)\
            VALUES\
            ({},'{}','{}')\
        ;".format(holidayID,holidayDate,guid))
        #Inserting the holidays to the corresponding geographical entry
        guid = getUUID()
        lpgDB.execute("\
            INSERT INTO tblGeographicLocHolidays\
            (HolidayID,GeographicLocationID,Guid)\
            VALUES\
            ({},{},'{}')\
        ;".format(holidayID,brusselsID,guid))

    lpgDB.commit()
    
    return

def getUUID():
    res = uuid.uuid4().__str__()
    return res

if __name__ == "__main__":
    main()

@noah80
Copy link
Contributor

noah80 commented Mar 12, 2024

Thanks for posting that. Hope that solves the problem for you. If not, you could also modify the LPG directly. It's fully open source. I don't have the resources right now to significantly extend the API, but would be glad to accept any merge request about that.

@frozznight
Copy link
Author

Dear @noah80,
I have another question.
Regarding the solar radiation data, how can I include my local radiation data to the database?
I am checking all the tables in the database, I could not find what the corresponding table is.

['sqlite_stat1',
 'tblHHTDeviceLocations',
 'sqlite_sequence',
 'SQLITEADMIN_QUERIES',
 'tblHHLocations',
 'tblLPGVersion',
 'ChargingStationSetEntry',
 'tblTransportationChargingStation',
 'tblAffTaggingEntries',
 'tblAffTagggingSetLoadType',
 'tblAffTagReferences',
 'tblSettings',
 'tblLoadTypes',
 'tblHolidays',
 'tblHolidayDates',
 'tblHolidayProbabilities',
 'tblDateBasedProfile',
 'tblDateProfilePoints',
 'tblVacations',
 'tblDesires',
 'tblDeviceActionDevices',
 'tblDeviceTaggingReferences',
 'tblHHTTags',
 'tblVacationTimes',
 'tblVariables',
 'tblTransportationDeviceSets',
 'tblTransportationDeviceSetEntries',
 'tblTimePoints',
 'tblTimeLimits',
 'tblTemperatures',
 'tblTimeBasedProfile',
 'tblTemplateTags',
 'tblSubAffordances',
 'tblLoadTypeOutcomes',
 'tblPersons',
 'tblAffordanceDesires',
 'tblAffordanceDeviceTimeprofile',
 'tblAffordanceOutcomes',
 'tblAffordanceStandby',
 'tblAffordanceSubaffordance',
 'tblAffordanceTag',
 'tblAffTaggingSet',
 'tblCalculationOutcomes',
 'tblGenerators',
 'tblGeographicLocHolidays',
 'tblDeviceTaggingEntries',
 'tblTemperatureProfiles',
 'tblAffordanceVariableOps',
 'tblAffordanceVariableReqs',
 'tblCHHTraits',
 'tblDeviceActionGroups',
 'tblDeviceCategories',
 'tblChargingStationSets',
 'tblDeviceActions',
 'tblDeviceTags',
 'tblEnergyStorageSignals',
 'tblHousehold',
 'tblHouseholdPlanEntries',
 'tblDeviceSelectionDeviceActions',
 'tblDeviceSelectionItems',
 'tblDeviceTaggingSetLoadType',
 'tblDeviceTaggingSets',
 'tblEnergyStorages',
 'tblDeviceSelections',
 'tblHHAffordances',
 'tblHHAutonomousDevices',
 'tblHHTTraits',
 'tblHouses',
 'tblLocations',
 'tblModularHouseholds',
 'tblTraitTags',
 'tblRealDeviceLoadType',
 'tblLocationDevices',
 'tblTimeLimitEntries',
 'tblHHDeviceLocations',
 'tblHHPersons',
 'tblHHVacations',
 'tblHouseTypes',
 'tblHouseTypeTransformationDevice',
 'tblHouseTypeGenerators',
 'tblHouseTypeDevices',
 'tblModularHouseholdTags',
 'tblSTHouseSizes',
 'tblSTHouseholdDistributions',
 'tblSTHouseholdTemplates',
 'tblSettlementHH',
 'tblTemplatePerson',
 'tblSubAffordanceDesires',
 'tblSubAffordanceVariableOps',
 'tblHouseholdTraits',
 'tblHHTLocations',
 'tblHouseholdTemplates',
 'tblTemplatePersonTrait',
 'tblHouseholdPlans',
 'tblHouseTypeEnergyStorages',
 'tblTransportationDeviceCategories',
 'tblSiteLocations',
 'tblTransportationDevices',
 'tblTransportationDeviceLoads',
 'tblTransformationDevices',
 'tblTransformationDeviceLoadType',
 'tblTransformationDeviceConditions',
 'tblTransformationFactor',
 'tblHHTAutonomousDevices',
 'tblHHTDesires',
 'tblHHTAffordances',
 'tblHHGEntryPerson',
 'tblHHTemplateTag',
 'tblSettlementTemplates',
 'tblSTHouseholdDistributionTags',
 'tblSTHouseTypes',
 'tblSTTraitLimits',
 'tblOptions',
 'tblHouseHouseholds',
 'tblSettlement',
 'tblTravelRoutes',
 'tblTravelRouteSteps',
 'tblChargingStationSetEntries',
 'tblHHTemplateVacations',
 'tblAffordances',
 'tblSTChargingStationSets',
 'tblSTTravelRouteSets',
 'tblSTTransportationDeviceSets',
 'tblLivingPatternTags',
 'tblHHTLivingPatternTags',
 'tblCHHPersons',
 'tblHHTemplatePerson',
 'tblHHGEntry',
 'tblDevices',
 'tblTravelRouteSet',
 'tblSites',
 'tblTravelRouteSetEntry',
 'tblGeographicLocations']

@noah80
Copy link
Contributor

noah80 commented Mar 12, 2024

Not sure what you want to do with other radiation data. That is only used in the LPG to determine, when the people turn on the lights at home. So the influence of that is rather small. If you want to properly model things like solar gains in the building, then I would like to recommend our complementary building simulator HiSim.

But if you really insist, it should be in the table tblDateBasedProfile and tblDateProfilePoints.

@frozznight
Copy link
Author

Thank you @noah80 for your reply,
I will look at the other tool.
From my side, there is no more discussion to follow up.
We can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants