Commit 256aa082 authored by hazrmard's avatar hazrmard
Browse files

KW to W, KW per Ton to W/W, removed pressure conversion as pressure units in...

KW to W, KW per Ton to W/W, removed pressure conversion as pressure units in trends are undocumented
parent 0081c167
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ Python package/script for downloading trends from Building Logix Data Exchange (
## Installation

```
pip install git+https://git.isis.vanderbilt.edu/SmartBuildings/bdx@v0.2.2
pip install git+https://git.isis.vanderbilt.edu/SmartBuildings/bdx@v0.2.3
```

## Usage
@@ -34,7 +34,7 @@ Date/time formats can be
 - 20200203T153000Z-6

# for example:
python -m bdx harrypotter wing@rd1umLeviosa 2422 2020-02-03T15:00Z-6 2020-02-04T16:00Z-6 ~/data.csv
python -m bdx harrypotter wing@rd1umLeviosa 2422 2020-02-03T15:00Z-6 2020-02-04T16:00Z-6 ~/data.csv --preprocess
```

If `file` is not provided, output is printed to `STDOUT` and can be piped elsewhere.
+14 −8
Original line number Diff line number Diff line
@@ -92,26 +92,32 @@ def parse_trend_dict(trend_dict: List[Dict[str, Any]]) -> pd.DataFrame:
    # 'trendValueId': int, identifier for field name
    # 'dataValues': time series as a list of dicts, 
    #     [
    #         {'time': str, 'realValue': Any, valueType: ['REAL' or 'NULL']},
    #         {'time': str, 'realValue': Any, valueType: ['REAL' or 'NULL']}
    #         {'time': str, 'realValue': Any, 'valueType': 'REAL'},
    #         {'time': str, 'boolValue': Any, 'valueType': 'BOOL'}
    #         {'time': str,                   'valueType': 'NULL'}
    #         ...
    #         Where:
    #           - time: ISO format 'yyyy-mm-ddThh:mm:ss.sssZ'
    #           - valueType: 'REAL' or 'NULL'. If 'REAL', then 'realValue' key exists
    #           - realValue: The value at that time stamp IF valueType != 'NULL'
    #           - valueType: 'REAL' or 'NULL' or 'BOOL'.
    #             - If 'REAL', then 'realValue' key exists,
    #             - If 'BOOL', then 'boolValue' key exists
    #           - realValue: The value at that time stamp IF valueType == 'REAL'
    #           - boolValue: The value at that time stamp IF valueType == 'BOOL'
    #     ]
    frames = []     # list of dataframes parsed from each trend dictionary
    for time_series in trend_dict:
        series_df = pd.DataFrame(time_series['dataValues'])  # create a DataFrame for each series
        series_df['time'] = pd.to_datetime(series_df['time'])
        series_df.set_index('time', inplace=True)
        # If dataframe does not have a 'realValue' column, it means that the
        # If dataframe does not have 'realValue', 'boolValue' column, it means that the
        # whole series was missing values (valueType='NULL'). So a placeholder
        # column is created with NaN values. These can then be handled on
        # per-column basis in the final DataFrame:
        if 'realValue' not in series_df:
            series_df['realValue'] = np.nan
        series_df.rename(columns={'realValue': time_series['label']}, inplace=True)
        if ('realValue' not in series_df) and ('boolValue' not in series_df):
            series_df['nullValue'] = np.nan
        series_df.rename(columns={'realValue': time_series['label'],
                                  'boolValue': time_series['label'],
                                  'nullValue': time_series['label']}, inplace=True)
        series_df.drop(columns='valueType', inplace=True, errors='ignore')
        frames.append(series_df)
    df = pd.concat(frames, axis='columns', join='outer', sort=True)
+8 −7
Original line number Diff line number Diff line
@@ -19,16 +19,17 @@ from .thermo import f2k, gpm2m3s, psi2pa, btuhr2w, ton2w
# Patterns in order of preference. If a patternn is matched, later patterns
# are not considered.
HEURISTICS = (
    ('Temp|_Humidity|Wet_Bulb|_Supply_SP',          f2k),
    ('Percent',                                     lambda pct: 0.01 * pct),
    ('KW_Ton',                                      lambda kw: kw),
    ('Kw$',                                         lambda kw: 1000 * kw),
    ('Temp|Wet_Bulb|_Supply_SP|TempSetPoint',       f2k),
    ('Percent|AirHumidity',                         lambda pct: 0.01 * pct),
    ('Power$',                                      lambda p: p),
    ('Kw$',                                         lambda kw: kw * 1000.0),
    ('KW_Ton',                                      lambda kw: 1000 * kw / ton2w(1)),
    ('Runtime',                                     lambda r: r * 60.0),
    ('Flow$',                                       gpm2m3s),
    ('Press$|Pressure$',                            psi2pa),
    ('Flow$|Flow Value$',                           gpm2m3s),
    # TODO: Pressure units in the trends are undocumented.
    # ('Press$|Pressure$',                            psi2pa),
    ('Load_Btuh',                                   btuhr2w),
    ('Load_Tons|Load\sValue|Capacity',              ton2w)
    ('Load_Tons|Load\sValue|Capacity|Ton',          ton2w)
)


+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ from distutils.core import setup


setup(name='bdx',
      version='0.2.2',
      version='0.2.3',
      description='Download trends from Building Logix data exchange (BDX)',
      author='Ibrahim Ahmed',
      author_email='ibrahim.ahmed@vanderbilt.edu',