bmonreporter/reporter.py
def process_server(server_url: str, template_path: Path, output_dir: str):
    """Create the reports for one BMON server with the base URL of 'server_url'.
    'template_path' is the Path to the Jupyter templates
    Copy the reports to the directory specified by 'output_dir', placed in a
    subdirectory named after the server_url.
    """

    try:
        # extract server domain for message labeling purposes
        server_domain = server_url  # in case next statement errors, we have something to log
        server_domain = urlparse(server_url).netloc

        logging.info(f'Processing started for {server_domain}')

        # Make a working directory and a reports directory for this server
        server_dir = tempfile.TemporaryDirectory(prefix=f'bm_{urlparse(server_url).netloc}_')
        server_path = Path(server_dir.name)
        rpt_path = server_path / 'reports'
        rpt_path.mkdir()
        working_path = server_path / 'working'
        working_path.mkdir()

        # loop through all the buildings of the BMON site, running the building
        # templates on each.
        server = bmondata.Server(server_url)
        bldgs = server.buildings()     # all buildings
        bldg_ids = [bldg['id'] for bldg in bldgs]
        bldg_rpt_dict = run_report_set(
            server_url,
            'building_id',
            bldg_ids,
            working_path,
            template_path / 'building',
            rpt_path / 'building',
            )
        # save the report dictionary into a pickle file and a JSON file
        pickle.dump(bldg_rpt_dict, open(rpt_path / 'building.pkl', 'wb'))
        json.dump(bldg_rpt_dict, open(rpt_path / 'building.json', 'w'))

        # List of the organization IDs including ID = 0 for all organizations.
        orgs = server.organizations()     # all organizations
        org_ids = [0] + [org['id'] for org in orgs]
        org_rpt_dict = run_report_set(
           server_url,
           'org_id',
           org_ids,
           working_path,
           template_path / 'organization',
           rpt_path / 'organization',
           )
        # save the report dictionary into a pickle file and a JSON file.
        pickle.dump(org_rpt_dict, open(rpt_path / 'organization.pkl', 'wb'))
        json.dump(org_rpt_dict, open(rpt_path / 'organization.json', 'w'))

        # Add some additional files that give full list of organizations and a 
        # mapping between each organization and the buildings associated with it.
        # This info will allow someone to build a report viewing application 
        # without having to make any API calls to the BMON server directly.  Also,
        # this information will be time-consistent with the generated reports.

        # Title and ID of every organization, including ID = 0, which represents
        # all organizations.
        all_orgs = [('All Organizations', 0)] + [(org['title'], org['id']) for org in orgs]
        pickle.dump(all_orgs, open(rpt_path / 'all_orgs.pkl', 'wb'))
        json.dump(all_orgs, open(rpt_path / 'all_orgs.json', 'w'))

        # Dictionary mapping an Organization to a list of Buildings, each building
        # having a title and an ID.  Organization 0 maps to all buildings.
        org_to_bldgs = {0: [(bldg['title'], bldg['id']) for bldg in bldgs]}
        for org in orgs:
            org_to_bldgs[org['id']] =  [(bldg[1], bldg[0]) for bldg in org['buildings']]
        pickle.dump(org_to_bldgs, open(rpt_path / 'org_to_bldgs.pkl', 'wb'))
        json.dump(org_to_bldgs, open(rpt_path / 'org_to_bldgs.json', 'w'))

    except:
        logging.exception(f'Error processing server {server_domain}')

    finally:
        try:
            # copy the report files to their final location
            dest_dir = str(Path(output_dir) / server_domain)

            # If the destination is s3, the Path concatenation above stripped out a /
            # that needs to be put back in.
            if dest_dir.startswith('s3:'):
                dest_dir = 's3://' + dest_dir[4:]
            
            copy_dir_tree(
                str(rpt_path), 
                dest_dir
            )

        except:
            logging.exception(f'Error copying report files to final destination, {server_domain}.')

        server_dir.cleanup()
Create the reports for one BMON server with the base URL of 'server_url'.
    'template_path' is the Path to the Jupyter templates
    Copy the reports to the directory specified by 'output_dir', placed in a
    subdirectory named after the server_url.
    
Create the reports for one BMON server with the base URL of 'server_url'.
'template_path' is the Path to the Jupyter templates
Copy the reports to the directory specified by 'output_dir', placed in a
subdirectory named after the server_url.
Create the reports for one BMON server with the base URL of ' server_url ' . ' template_path ' is the Path to the Jupyter templates Copy the reports to the directory specified by ' output_dir ' placed in a subdirectory named after the server_url .
def process_server(server_url: str, template_path: Path, output_dir: str):
    try:
        server_domain = server_url  
        server_domain = urlparse(server_url).netloc
        logging.info(f'Processing started for {server_domain}')
        server_dir = tempfile.TemporaryDirectory(prefix=f'bm_{urlparse(server_url).netloc}_')
        server_path = Path(server_dir.name)
        rpt_path = server_path / 'reports'
        rpt_path.mkdir()
        working_path = server_path / 'working'
        working_path.mkdir()
        server = bmondata.Server(server_url)
        bldgs = server.buildings()     
        bldg_ids = [bldg['id'] for bldg in bldgs]
        bldg_rpt_dict = run_report_set(
            server_url,
            'building_id',
            bldg_ids,
            working_path,
            template_path / 'building',
            rpt_path / 'building',
            )
        pickle.dump(bldg_rpt_dict, open(rpt_path / 'building.pkl', 'wb'))
        json.dump(bldg_rpt_dict, open(rpt_path / 'building.json', 'w'))
        orgs = server.organizations()     
        org_ids = [0] + [org['id'] for org in orgs]
        org_rpt_dict = run_report_set(
           server_url,
           'org_id',
           org_ids,
           working_path,
           template_path / 'organization',
           rpt_path / 'organization',
           )
        .
        pickle.dump(org_rpt_dict, open(rpt_path / 'organization.pkl', 'wb'))
        json.dump(org_rpt_dict, open(rpt_path / 'organization.json', 'w'))
        .
        all_orgs = [('All Organizations', 0)] + [(org['title'], org['id']) for org in orgs]
        pickle.dump(all_orgs, open(rpt_path / 'all_orgs.pkl', 'wb'))
        json.dump(all_orgs, open(rpt_path / 'all_orgs.json', 'w'))
        org_to_bldgs = {0: [(bldg['title'], bldg['id']) for bldg in bldgs]}
        for org in orgs:
            org_to_bldgs[org['id']] =  [(bldg[1], bldg[0]) for bldg in org['buildings']]
        pickle.dump(org_to_bldgs, open(rpt_path / 'org_to_bldgs.pkl', 'wb'))
        json.dump(org_to_bldgs, open(rpt_path / 'org_to_bldgs.json', 'w'))
    except:
        logging.exception(f'Error processing server {server_domain}')
    finally:
        try:
            dest_dir = str(Path(output_dir) / server_domain)
            if dest_dir.startswith('s3:'):
                dest_dir = 's3://' + dest_dir[4:]
            copy_dir_tree(
                str(rpt_path), 
                dest_dir
            )
        except:
            logging.exception(f'Error copying report files to final destination, {server_domain}.')
        server_dir.cleanup()
def process_server ( server_url : str , template_path : Path , output_dir : str ) : try : server_domain = server_url server_domain = urlparse ( server_url ) . netloc logging . info ( f'Processing started for {server_domain}' ) server_dir = tempfile . TemporaryDirectory ( prefix = f'bm_{urlparse(server_url).netloc}_' ) server_path = Path ( server_dir . name ) rpt_path = server_path / 'reports' rpt_path . mkdir ( ) working_path = server_path / 'working' working_path . mkdir ( ) server = bmondata . Server ( server_url ) bldgs = server . buildings ( ) bldg_ids = [ bldg [ 'id' ] for bldg in bldgs ] bldg_rpt_dict = run_report_set ( server_url , 'building_id' , bldg_ids , working_path , template_path / 'building' , rpt_path / 'building' , ) pickle . dump ( bldg_rpt_dict , open ( rpt_path / 'building.pkl' , 'wb' ) ) json . dump ( bldg_rpt_dict , open ( rpt_path / 'building.json' , 'w' ) ) orgs = server . organizations ( ) org_ids = [ 0 ] + [ org [ 'id' ] for org in orgs ] org_rpt_dict = run_report_set ( server_url , 'org_id' , org_ids , working_path , template_path / 'organization' , rpt_path / 'organization' , ) pickle . dump ( org_rpt_dict , open ( rpt_path / 'organization.pkl' , 'wb' ) ) json . dump ( org_rpt_dict , open ( rpt_path / 'organization.json' , 'w' ) ) all_orgs = [ ( 'All Organizations' , 0 ) ] + [ ( org [ 'title' ] , org [ 'id' ] ) for org in orgs ] pickle . dump ( all_orgs , open ( rpt_path / 'all_orgs.pkl' , 'wb' ) ) json . dump ( all_orgs , open ( rpt_path / 'all_orgs.json' , 'w' ) ) org_to_bldgs = { 0 : [ ( bldg [ 'title' ] , bldg [ 'id' ] ) for bldg in bldgs ] } for org in orgs : org_to_bldgs [ org [ 'id' ] ] = [ ( bldg [ 1 ] , bldg [ 0 ] ) for bldg in org [ 'buildings' ] ] pickle . dump ( org_to_bldgs , open ( rpt_path / 'org_to_bldgs.pkl' , 'wb' ) ) json . dump ( org_to_bldgs , open ( rpt_path / 'org_to_bldgs.json' , 'w' ) ) except : logging . exception ( f'Error processing server {server_domain}' ) finally : try : dest_dir = str ( Path ( output_dir ) / server_domain ) if dest_dir . startswith ( 's3:' ) : dest_dir = 's3://' + dest_dir [ 4 : ] copy_dir_tree ( str ( rpt_path ) , dest_dir ) except : logging . exception ( f'Error copying report files to final destination, {server_domain}.' ) server_dir . cleanup ( )
Create the reports for one BMON server with the base URL of 'server_url'.
Create the reports for one BMON server with the base URL of ' server_url ' .
"""Create the reports for one BMON server with the base URL of 'server_url'.
    'template_path' is the Path to the Jupyter templates
    Copy the reports to the directory specified by 'output_dir', placed in a
    subdirectory named after the server_url.
    """ # extract server domain for message labeling purposes # in case next statement errors, we have something to log # Make a working directory and a reports directory for this server # loop through all the buildings of the BMON site, running the building # templates on each. # all buildings # save the report dictionary into a pickle file and a JSON file # List of the organization IDs including ID = 0 for all organizations. # all organizations # save the report dictionary into a pickle file and a JSON file. # Add some additional files that give full list of organizations and a  # mapping between each organization and the buildings associated with it. # This info will allow someone to build a report viewing application  # without having to make any API calls to the BMON server directly.  Also, # this information will be time-consistent with the generated reports. # Title and ID of every organization, including ID = 0, which represents # all organizations. # Dictionary mapping an Organization to a list of Buildings, each building # having a title and an ID.  Organization 0 maps to all buildings. # copy the report files to their final location # If the destination is s3, the Path concatenation above stripped out a / # that needs to be put back in.
server_url
str
template_path
Path
output_dir
str