Is there a better way to get design days from sim results?

Currently doing some things externally from Rh/Gh:
From the results of an annual simulation, I’m basically wanting to create analysis periods to use to via apply analysis period methodology on the annual data.

Below I have some “it works but I’m sure there is a more elegant way”, as atleast in jupyter its taking ~ 1.5 seconds to return… and I’m wanting to apply this to about 1,500 results at a time as quickly as possible :sweat_smile:
I don’t frequently write stuff that uses SQL sooo this may be kinda ugly:

def get_peak_days(sql) -> tuple:
    conn = sqlite3.connect(str(sql))
    cur = conn.cursor()

    for i, row in enumerate(cur.execute('SELECT * FROM ZoneSizes;')):
        if row[2] == 'Cooling':
            cx = row
        if row[2] == 'Heating':
            hx = row
    cx_month = cx[8].split(' ')[0].split('/')[0]
    cx_day = cx[8].split(' ')[0].split('/')[1]
    hx_month = hx[8].split(' ')[0].split('/')[0]
    hx_day = hx[8].split(' ')[0].split('/')[1]

    cx_per = ap.AnalysisPeriod(st_month=cx_month,
                               st_day=cx_day, end_month=cx_month, end_day=cx_day)

    hx_per = ap.AnalysisPeriod(st_month=hx_month,
                               st_day=hx_day, end_month=hx_month, end_day=hx_day)

    return (cx_per, hx_per)

rsl = 'assets/eplusout.sql'

stuff = get_peak_days(rsl)
>>  (7/21 to 7/21 between 0 and 23 @1, 1/21 to 1/21 between 0 and 23 @1)

I imagine that your SQL query could be a little better since it seems like you are loading all of the data in the ZoneSizes table right now and you can narrow this down with a WHERE statement like you see used here in the core libraries

Still, I don’t think the ZoneSizes table is that big so this might not change your run time much. You should probably check out the tables in the sqlite file using a sqlite file browser like DB Browser to see what tweaks to your query will be the most helpful for only loading the data you care about.

1 Like