コード例 #1
0
ファイル: frequency_table.py プロジェクト: ArtShp/DataScience
    def render(self):
        items = []

        for row in self.content["rows"]:
            if row["extra_class"] == "missing":
                items.append((
                    widgets.Label(str(row["label"])),
                    widgets.FloatProgress(value=row["count"],
                                          min=0,
                                          max=row["n"],
                                          bar_style="danger"),
                    widgets.Label(str(row["count"])),
                ))
            elif row["extra_class"] == "other":
                items.append((
                    widgets.Label(str(row["label"])),
                    widgets.FloatProgress(value=row["count"],
                                          min=0,
                                          max=row["n"],
                                          bar_style="info"),
                    widgets.Label(str(row["count"])),
                ))
            else:
                items.append((
                    widgets.Label(str(row["label"])),
                    widgets.FloatProgress(value=row["count"],
                                          min=0,
                                          max=row["n"],
                                          bar_style=""),
                    widgets.Label(str(row["count"])),
                ))

        return get_table(items)
コード例 #2
0
    def render(self):
        items = []

        for row in self.content["rows"]:
            if row["extra_class"] == "missing":
                items.append(
                    widgets.HBox([
                        widgets.FloatProgress(
                            value=row["count"],
                            min=0,
                            max=row["n"],
                            description=str(row["label"]),
                            bar_style="danger",
                        ),
                        widgets.Label(str(row["count"])),
                    ]))
            elif row["extra_class"] == "other":
                items.append(
                    widgets.HBox([
                        widgets.FloatProgress(
                            value=row["count"],
                            min=0,
                            max=row["n"],
                            description=str(row["label"]),
                            bar_style="info",
                        ),
                        widgets.Label(str(row["count"])),
                    ]))
            else:
                items.append(
                    widgets.HBox([
                        widgets.FloatProgress(
                            value=row["count"],
                            min=0,
                            max=row["n"],
                            description=str(row["label"]),
                            bar_style="",
                        ),
                        widgets.Label(str(row["count"])),
                    ]))

        ft = widgets.VBox(items)

        # Overwrite info to disabled
        # TODO: resize width of progress bar / label
        # display(
        #     HTML(
        #         "<style>.progress-bar-info{background-color: #ddd !important;} .dataframe td{     white-space: nowrap !important;}</style>"
        #     )
        # )
        return ft
コード例 #3
0
def frequency_table_nb(rows: List[dict]) -> widgets.VBox:
    items = []

    for row in rows:
        if row["extra_class"] == "missing":
            items.append(
                widgets.HBox([
                    widgets.FloatProgress(
                        value=row["count"],
                        min=0,
                        max=row["n"],
                        description=str(row["label"]),
                        bar_style="danger",
                    ),
                    widgets.Label(str(row["count"])),
                ]))
        elif row["extra_class"] == "other":
            items.append(
                widgets.HBox([
                    widgets.FloatProgress(
                        value=row["count"],
                        min=0,
                        max=row["n"],
                        description=str(row["label"]),
                        bar_style="info",
                    ),
                    widgets.Label(str(row["count"])),
                ]))
        else:
            items.append(
                widgets.HBox([
                    widgets.FloatProgress(
                        value=row["count"],
                        min=0,
                        max=row["n"],
                        description=str(row["label"]),
                        bar_style="",
                    ),
                    widgets.Label(str(row["count"])),
                ]))

    return widgets.VBox(items)
コード例 #4
0
ファイル: wrappers.py プロジェクト: spapa013/wridgets
    def __init__(self,
                 on_interact=None,
                 output=None,
                 overwrite_previous_output=True,
                 feedback=False,
                 run=True,
                 action_kws={},
                 *args,
                 **kwargs):
        super().__init__(on_interact=on_interact,
                         output=output,
                         overwrite_previous_output=overwrite_previous_output,
                         feedback=feedback,
                         action_kws=action_kws)

        self.widget = widgets.FloatProgress(*args, **kwargs)

        if run:
            self.run()
コード例 #5
0
 def __init__(self):
     super(StatusBar, self).__init__()
     self.children = [
         widgets.FloatProgress(
             value=0,
             min=0,
             max=100.0,
             step=0.1,
             description='Status:',
             bar_style='info',
             orientation='horizontal',
             style=self.style,
         ),
         widgets.HTML(
             value='<font color="blue"></front>',
             description='',
             style=self.style,
         )]
     self.layout.visibility = 'visible'
     display(self)
コード例 #6
0
def automator_gui(filename):
    """
    :parameter project_filename:
        The name of a puckle file containing an OQtProject
    """
    global w_model, w_sources, w_nb_name, w_nb_type, w_repo, w_progress
    global project_filename, model
    global project_dir
    wdg_list = []

    margin = 5

    project_filename = filename
    oqmbtp = OQtProject.load_from_file(project_filename)
    models = oqmbtp.models.keys()
    project_dir = oqmbtp.directory

    w_title = widgets.HTML(value="<h3>Automator<h3>")
    tmp_str = "Name     : %s <br>" % (oqmbtp.name)
    tmp_str += "Stored in: %s <br><br>" % (project_dir)
    w_text = widgets.HTML(value=tmp_str)
    wdg_list.append(w_title)
    wdg_list.append(w_text)

    tmp_str = "Warning: the model does not contain sources"
    w_warn = widgets.HTML(value=tmp_str, visible=False)

    if len(models):
        model_id = models[0]
        model = oqmbtp.models[model_id]
        w_model = widgets.Dropdown(options=models,
                                   description='Model',
                                   value=model_id,
                                   width=400,
                                   margin=margin)
        if len(model.sources.keys()):

            # Sources drop down menu
            tmp_list = sorted(model.sources.keys())
            tmp_list.insert(0, 'All')
            tmp_str = 'Sources'
            w_sources = widgets.SelectMultiple(options=tmp_list,
                                               description=tmp_str,
                                               width=200,
                                               margin=margin)
        else:
            w_sources = widgets.Dropdown(options=[], description='Source')
        wdg_list.append(w_model)
        wdg_list.append(w_sources)
    else:
        w_warn.visible = True

    # Notebook type
    w_nb_type = widgets.Dropdown(options=NB_TYPES,
                                 description='Notebook type',
                                 width=400,
                                 margin=margin)
    wdg_list.append(w_nb_type)

    # Notebook name
    w_nb_name = widgets.Dropdown(options=[],
                                 description='Notebook name',
                                 width=400,
                                 margin=margin)
    wdg_list.append(w_nb_name)

    # Report checkbox
    w_repo = widgets.Checkbox(description='Generate report', value=False)
    wdg_list.append(w_repo)

    # Warning
    wdg_list.append(w_warn)

    # Button
    w_butt = widgets.Button(description='Run', width=100, border_color='red')
    wdg_list.append(w_butt)

    # Progress bar
    w_progress = widgets.FloatProgress(value=0.0,
                                       min=0.0,
                                       step=1,
                                       visible=False,
                                       description='Processing:')
    wdg_list.append(w_progress)

    w_model.on_trait_change(handle_change_model)
    w_nb_type.on_trait_change(handle_change_nb_type, 'value')
    w_butt.on_click(handle_run)

    # Clean variables
    del oqmbtp

    return widgets.VBox(children=wdg_list)
コード例 #7
0
def ConcatIfMatch(user, date, notes, projectname, inputfile, outputfilepath,
                  outputfiletype):
    #concats and outputs file type with predetermined file name if name is appropriate: returns output file
    #converts input filetype to dataframe: returns dataframe array of input data
    #checks for matching headers: returns boolean
    #widget to prompt out file name: returns user defined out file name. If none, returns auto generated file name
    global FinalFileName

    #b=[]
    matchTF = []
    b_col = []

    minCONCAT = 0
    if outputfiletype == '.csv':
        maxCONCAT = len(inputfile.files)
    elif outputfiletype == '.xlsx':
        maxCONCAT = 37

    global progressbarCONCAT

    progressbarCONCAT = widgets.FloatProgress(
        min=minCONCAT,
        max=maxCONCAT,
        description='Concatenating files',
        style={'description_width': 'initial'})
    display(progressbarCONCAT)
    stepup = 0
    progressbarCONCAT.value = 0

    global inputfile_df
    inputfile_df = pd.read_csv(inputfile.files[0],
                               sep=',')  # loads data from csv to dataframe
    # note: I removed the append feature so you can only upload 1 file at a time

    # I commented this out simply because it ran an IndexError but I realize this workflow doesn't really need
    # the failsafe given the application will likely not be for multiple file upload applications
    #b_col.append(b[n].columns) #creates an array of column names of b : b_col
    #matchTF.append(pd.Index.equals(b_col[0], b_col[n])) #compares if ALL column names match

    #variable for loading bar
    if outputfiletype == '.csv':
        stepup += 1
        progressbarCONCAT.value += 1

    elif outputfiletype == '.xlsx':
        for n in range(minCONCAT, maxCONCAT):
            stepup += 1
            progressbarCONCAT.value += 1
            time.sleep(1)

    FinalFileName = projectname + '_output_file' + outputfiletype

    if NameIsValid(FinalFileName) is True:
        # given the single file upload nature, this line has also been commented out
        #fout6 = pd.concat(b)

        #write into seperate function later
        selDirectory = outputfilepath
        newFolderInDir = projectname
        newDirectory = selDirectory + '//' + newFolderInDir
        os.mkdir(newDirectory)
        os.chdir(newDirectory)

        #calling shortened function for session information function, to create .txt file w user info
        UserInfoFile(user, date, projectname, notes)

        if outputfiletype == '.xlsx':
            writer = pd.ExcelWriter(FinalFileName, engine='xlsxwriter')
            writer.save()
        elif outputfiletype == '.csv':
            inputfile_csv = inputfile_df.to_csv(FinalFileName)
        else:
            # this is more of a courtesy than anything; the default is set to csv
            # and due to the nature of radio buttons, it's impossible NOT to select
            # an output file type option.
            print(
                "Output File Type Error: Missing Output File Type Selection.")
        if all(matchTF) is False:
            print('File input header warning: headers do not match')
    elif NameIsValid(FinalFileName) is False:
        print('File name error: invalid file name')
        print('Special Characters ( : / \ " | < > ? * ) not allowed!')

    progressbarCONCAT.close()

    return
コード例 #8
0
def add_progress_bar():
    return widgets.FloatProgress(value=0.0,min=0.0,max=1.0,layout=widgets.Layout(width='auto',height='auto'))