Commit a1dc9ca6 authored by hazrmard's avatar hazrmard
Browse files

bugfix to handle cases where one queried property returns empty,

Create empty dataframe with the property name filled with NaN so it shows up in the final dataframe in parse_trend_dict
parent 7a39c4f0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@
*.pyc
__pycache__
*.ipynb

*.csv
.vscode/
 No newline at end of file
+7 −2
Original line number Diff line number Diff line
@@ -11,8 +11,13 @@ parser = ArgumentParser(
    description=('Download data from Building Logix Data Exchange (BDX) '
                 'and save it to csv.'),
    epilog=('Date/time formats can be\n'
            ' - 2020-02-03T15:30:00Z-6 (i.e. Feb 3 2020 3:30 PM UTC-6 timezone)\n'
            ' - 20200203T153000Z-6\n'),
            ' - 2020-02-03T15:30:00-6 (i.e. Feb 3 2020 3:30 PM UTC-6 timezone)\n'
            ' - 2020-02-03T15:30:00-06:00\n'
            ' - 2020-02-03 15:30:00-06:00\n'
            ' - 20200203T153000-6\n'
            ' - 20200203153000-6\n'
            'ATTENTION: Using a "Z" to specify time zone uses Unix conventions, so:\n'
            ' - 2020-02-03T15:30:00Z-6 is Feb 3 2020 3:30 PM >>UTC+6<< timezone\n'),
    formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('user', type=str, help='Username for BDX')
parser.add_argument('password', type=str, help='Password for BDX')
+12 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ from typing import List, Dict, Any
from datetime import datetime
from urllib.parse import urlencode
import json
import warnings

import pandas as pd
import numpy as np
@@ -106,8 +107,16 @@ def parse_trend_dict(trend_dict: List[Dict[str, Any]]) -> pd.DataFrame:
    #     ]
    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'])
        # create a DataFrame for each series
        series_df = pd.DataFrame(time_series['dataValues'])
        # Possible that some queried properties may return empty, so their
        # 'dataValues' will be an empty list, and therefore wouldn't be able
        # to create a dataframe. Creating a placeholder frame so at least
        # the label makes into the final data frame as an empty column.
        if len(series_df) == 0:
            warnings.warn('Values for "{}" are empty, adding empty column.'\
                          .format(time_series['label']))
            series_df = pd.DataFrame({'time': []})
        series_df.set_index('time', inplace=True)
        # If dataframe does not have 'realValue', 'boolValue' column, it means that the
        # whole series was missing values (valueType='NULL'). So a placeholder
@@ -121,4 +130,5 @@ def parse_trend_dict(trend_dict: List[Dict[str, Any]]) -> pd.DataFrame:
        series_df.drop(columns='valueType', inplace=True, errors='ignore')
        frames.append(series_df)
    df = pd.concat(frames, axis='columns', join='outer', sort=True)
    df.index = pd.to_datetime(df.index)
    return df
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ CONSTANTS = _Constants(cv=4.1796e6, cm=4.1813e3)

# Constants used by vaporpressure() and dewpoint()
_ABConstants = namedtuple('ArdenBuckConstants', 'a b c d')
ABC = _ABConstants(a=6.1121, b=18.678, c=257.14, d=234.5)
ABC = _ABConstants(a=0.61121, b=18.678, c=257.14, d=234.5)

# Temperature conversion functions
# f: Farenheit
+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.3',
      version='0.2.4',
      description='Download trends from Building Logix data exchange (BDX)',
      author='Ibrahim Ahmed',
      author_email='ibrahim.ahmed@vanderbilt.edu',