Exemplo n.º 1
0
def read(report_type: str, report_id: str, results_path: str = None) -> dict:
    """

    :param report_type:
    :param report_id:
    :param results_path:
    :return:
    """

    first_character = report_type[0].lower()
    if first_character == 't':
        report_type = 'trial'
    elif first_character == 'g':
        report_type = 'group'

    if not results_path:
        results_path = paths.results()
    path = os.path.join(
        paths.clean(results_path),
        'reports',
        report_type,
        report_id,
        '{}.json'.format(report_id)
    )

    if not os.path.exists(path):
        return None

    out = read_path(path)
    out['id'] = report_id
    return out
Exemplo n.º 2
0
def add_coupling_plots(
        report: reporting.Report,
        trials: typing.List[dict]
):
    """
    Generates coupling report data from the analyzed coupling data and the
    individual simulation trial results

    :param report:
        Grouped coupling data from the grouped simulation results
    :param trials:
        Simulation results for each trial run by the group
    """

    distribution_traces = []
    population_traces = []
    index = 0

    for trial in trials:
        trial_data = reader.trial(trial['id'], paths.results())

        index += 1
        coupling_data = trial_data['couplings']

        distribution_traces.append(dict(
            x=coupling_data['distribution_profile']['x'],
            y=coupling_data['distribution_profile']['y'],
            type='scatter',
            mode='lines',
            name='{}'.format(index)
        ))

        population_traces.append(dict(
            x=coupling_data['population'],
            type='box',
            name='{}'.format(index),
            boxpoints=False
        ))

    report.add_plotly(
        data=distribution_traces,
        layout=plotting.create_layout(
            title='Coupling Length Trial Distributions',
            x_label='Expectation Value (au)',
            y_label='Coupling Length (m)'
        )
    )

    report.add_plotly(
        data=population_traces,
        layout=plotting.create_layout(
            title='Coupling Length Trials',
            x_label='Coupling Length (m)',
            y_label='Trial Index (#)'
        )
    )
Exemplo n.º 3
0
 def url(self):
     """
     Returns the URL that will open this report file in the browser for
     viewing
     :return:
     """
     return 'file://{path}?id={id}'.format(
         path=paths.results('{}.html'.format(self.type)),
         id=self.id
     )
Exemplo n.º 4
0
def execute_command():
    """

    :return:
    """

    system.log("""
        ==============
        REMOVE RESULTS
        ==============

        This command will remove all analysis, group and trial reports stored
        located in the directory:

        {}
        """.format(paths.results()), whitespace_bottom=1)

    do_it = query.confirm(
        'Are you sure you want to continue',
        default=False
    )

    if not do_it:
        system.log('[ABORTED]: No files were deleted')
        return system.end(0)

    path = paths.results('reports')

    if os.path.exists(path):
        try:
            shutil.rmtree(path)
        except Exception:
            try:
                shutil.rmtree(path)
            except Exception:
                pass

    system.log("""
        [SUCCESS]: All results have been removed
        """, whitespace_top=1)
Exemplo n.º 5
0
def execute_command():
    """ Runs the deploy command """

    parser = ArgumentParser()

    parser.description = cli.reformat(DESCRIPTION)

    parser.add_argument(
        'deploy',
        type=str,
        help='The deploy command to execute'
    )

    parser.add_argument(
        'root_path',
        type=str,
        help=cli.reformat("""
            The folder in the S3 bucket where your files will be uploaded
            """)
    )

    parser.add_argument(
        '-p', '--profile',
        dest='profile',
        type=str,
        default=None,
        help=cli.reformat("""
            The name of the AWS credentials profile to use for access to the
            AWS S3 bucket resources
            """)
    )

    parser.add_argument(
        '-b', '--bucket',
        dest='bucket',
        type=str,
        default=None,
        help=cli.reformat("""
            The name of the S3 bucket where the files will be uploaded
            """)
    )

    args = vars(parser.parse_args())
    configs = system.load_configs()

    upload_in_folder(
        get_aws_settings(configs, **args),
        paths.results('report')
    )
    system.log('[COMPLETE]: Trials have been deployed')
Exemplo n.º 6
0
def list_trials():
    system.log("===== TRIALS =====", whitespace_bottom=1)

    results_path = paths.results("trials.html")

    for uid, data_path in reader.listings("trial").items():
        url = "file://{}?id={}".format(results_path, uid)

        system.log(
            """
            --- {uid} ---
              {url}
            """.format(
                uid=uid, url=url
            ),
            whitespace_bottom=1,
        )
Exemplo n.º 7
0
def save_temp_json_file(filename: str, data: dict):
    """
    Saves the data dictionary to a temporary JSON file with the specified
    filename

    :param filename:
        The name of the temp file to save. The filename can also contain folder
        components, representing a path relative to the temporary root path
        for the running tracksim application
    :param data:
        The data to be stored in the temp file
    """

    temp_path = paths.results('temp', filename)
    temp_folder = os.path.dirname(temp_path)
    if not os.path.exists(temp_folder):
        os.makedirs(temp_folder)
Exemplo n.º 8
0
def listings(
        report_type: str,
        results_path: str = None,
        matching_glob: str = None
) -> dict:
    """
    Returns a dictionary that contains the report ids and absolute paths to
    the corresponding data files.

    :param report_type:
    :param results_path:
    :param matching_glob:
    :return:
    """

    report_type = report_type.lower()[0]
    report_type = 'group' if report_type == 'g' else 'trial'

    if not results_path:
        results_path = paths.results()
    else:
        results_path = paths.clean(results_path)
    directory = os.path.join(results_path, 'reports', report_type)

    out = dict()

    if matching_glob:
        matching_glob = os.path.join(
            directory,
            matching_glob.strip(os.sep)
        )

        for item_path in glob.iglob(matching_glob):
            item_path = item_path.rstrip(os.sep)
            item = os.path.basename(item_path)
            out[item] = os.path.join(item_path, '{}.json'.format(item))

        return out

    for item in os.listdir(directory):
        item_path = os.path.join(directory, item, '{}.json'.format(item))
        out[item] = item_path

    return out
Exemplo n.º 9
0
    def write(self, results_path: str = None) -> str:
        """

        :param results_path:
        :return:
        """

        if len(self.body) < 1:
            return None

        if not results_path:
            results_path = paths.results()

        path = os.path.join(results_path, 'reports', self.type, self.id)

        if os.path.exists(path):
            try:
                shutil.rmtree(path)
            except Exception:
                try:
                    shutil.rmtree(path)
                except Exception:
                    return None

        os.makedirs(path)

        template = self.env.get_template('report.template')

        report_path = os.path.join(path, '{}.js'.format(self.id))
        with open(report_path, 'w+') as f:
            f.write(template.render(
                DATA=json.dumps({
                    'data': self.data,
                    'body': '\n'.join(self.body)
                })
            ))

        for filename, contents in self.files.items():
            file_path = os.path.join(path, filename)
            with open(file_path, 'w+') as f:
                f.write(contents)

        return self.url
Exemplo n.º 10
0
def all_by_type(
        report_type: str,
        results_path: str = None
) -> typing.List[dict]:
    """
    Fetches the reported results for all simulations of the specified report
    type and returns them as a list of results dictionaries.

    :param report_type:
        The type of report to gather. Valid types are 'groups' and 'trials'

    :param results_path:
        The report path where the results will be found. If no path is
        specified, the default report path will be used.
    """

    first_character = report_type[0].lower()
    if first_character == 't':
        report_type = 'trial'
    elif first_character == 'g':
        report_type = 'group'

    if not results_path:
        results_path = paths.results()

    path = os.path.join(results_path, 'reports', report_type)

    if not os.path.exists(path):
        return []

    out = []

    for report_id in os.listdir(path):
        data = read(report_type, report_id, results_path=results_path)
        if data:
            out.append(data)

    return out
Exemplo n.º 11
0
def list_results(path: str = None, trials: bool = True):
    """

    :param path:
    :param trials:
    :return:
    """

    out = []

    if not path:
        path = paths.results('report')
    path = os.path.join(path, 'trials' if trials else 'groups')

    if not os.path.exists(path):
        return []

    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if not os.path.isdir(item_path):
            continue
        json_path = os.path.join(item_path, '{}.json'.format(item))
        if not os.path.exists(json_path):
            continue

        with open(json_path, 'r+') as f:
            url = json.load(f)['url']

        out.append(dict(
            id=item,
            url=url,
            directory=item_path,
            path=json_path
        ))

    return out
Exemplo n.º 12
0
 def directory(self):
     """
     Returns the directory where the report file will be written
     :return:
     """
     return paths.results('reports', self.type, self.id)
Exemplo n.º 13
0
def execute_command():
    """

    :return:
    """

    parser = ArgumentParser()

    parser.description = cli.reformat(DESCRIPTION)

    parser.add_argument(
        'export',
        type=str,
        help='The export command to execute'
    )

    parser.add_argument(
        'path',
        type=str,
        help=cli.reformat("""
            The relative or absolute path to the location where the exported
            reports directory will be created
            """)
    )

    parser.add_argument(
        '-d', '--directory',
        dest='directory_name',
        type=str,
        default='reports',
        help=cli.reformat("""
            The name of the directory to be created to store the results
            """)
    )

    parser.add_argument(
        '-s', '--source',
        dest='source_directory',
        type=str,
        default=paths.results(),
        help=cli.reformat("""
            The source reports directory to be exported. This flag allows you
            to export results that are stored in locations other than the
            default report location
            """)
    )

    parser.add_argument(
        '-f', '--force',
        dest='force',
        action='store_true',
        default=False,
        help=cli.reformat("""
            When included, the export process will overwrite any existing data
            at the specified path and directory. It should only be used to
            replace an existing exported reports directory with newer data
            """)
    )

    parser.add_argument(
        '-od', '--omit-data',
        dest='omit_data',
        action='store_true',
        default=False,
        help=cli.reformat("""
            When included, the export process will skip all of the raw data
            files for each group and trial. These files are not necessary for
            viewing the reports. They exist for post-simulation analyses.
            """)
    )

    parser.add_argument(
        '-oh', '--omit-html',
        dest='omit_html',
        action='store_true',
        default=False,
        help=cli.reformat("""
            When included, the export process will skip all of the html viewing
            related files and only export the data files for each group and
            trial. This is useful if you want to share or store data for
            analysis.
            """)
    )

    run(**vars(parser.parse_args()))