コード例 #1
0
ファイル: test_tables.py プロジェクト: nghenzi/panel
def test_dataframe_editors(dataframe, document, comm):
    editor = SelectEditor(options=['A', 'B', 'C'])
    table = DataFrame(dataframe, editors={'str': editor})
    model = table.get_root(document, comm)

    model_editor = model.columns[-1].editor
    assert isinstance(model_editor, SelectEditor) is not editor
    assert isinstance(model_editor, SelectEditor)
    assert model_editor.options == ['A', 'B', 'C']
コード例 #2
0
ファイル: test_tables.py プロジェクト: weiplanet/panel
def test_dataframe_editors(dataframe, document, comm):
    editor = SelectEditor(options=['A', 'B', 'C'])
    table = DataFrame(dataframe, editors={'str': editor})
    model = table.get_root(document, comm)

    assert model.columns[-1].editor is editor
コード例 #3
0
ファイル: view.py プロジェクト: tiandiyixian/osspolice
    def create_ui(self, data):
        self.logger.info("number of data items %d", len(data))

        # Create data source and data table
        # path, score, software_id, featcnt, featfreq, app name, app path, decision, status, comment, active in play, still voilating
        decision_editor = SelectEditor(options=[
            "Unprocessed", "GPL Violation", "LGPL Violation",
            "Open Source App", "False Positive", "False Negative (LGPL)",
            "False Negative (GPL)"
        ])
        status_editor = SelectEditor(options=[
            "Unprocessed", "Emailed", "Confirmed", "Denied", "Authorized"
        ])
        if self.app_info:
            columns = [
                TableColumn(field="myindex", title="Id"),
                TableColumn(field="path", title="File Path"),
                TableColumn(field="score", title="Score"),
                TableColumn(field="normscore",
                            title="NormScore",
                            formatter=NumberFormatter(format="0.00")),
                TableColumn(field="partial", title="PartialMatch"),
                TableColumn(field="repo_id", title="Repo ID"),
                TableColumn(field="software_name", title="OSS"),
                TableColumn(field="version", title="Version"),
                TableColumn(
                    field="featcnt",
                    title="FeatCount",
                ),
                TableColumn(
                    field="featfreq",
                    title="FeatFreq",
                ),
                TableColumn(field="package_name", title="Package"),
                TableColumn(field="app_path", title="App Path"),
                TableColumn(field="app_count", title="App Count"),
                TableColumn(field="decision",
                            title="Decision",
                            editor=decision_editor),
                TableColumn(field="status",
                            title="Status",
                            editor=status_editor),
                TableColumn(field="comment", title="Comment"),
                # I am not sure whether we should add these two fields here.
                # TableColumn(field="active", title="Active in Play"),
                # TableColumn(field="still_violating", title="Still Violating"),
            ]
        else:
            template_str = '<a href="' + self.REPO_URL + '/<%= value %>"><%= value %></a>'
            columns = [
                TableColumn(
                    field="myindex",
                    title="Id",
                ),
                TableColumn(field="name", title="Name"),
                TableColumn(field="score",
                            title="Score",
                            formatter=NumberFormatter(format="0.00")),
                TableColumn(field="normscore",
                            title="NormScore",
                            formatter=NumberFormatter(format="0.00")),
                TableColumn(field="partial", title="PartialMatch"),
                TableColumn(field="repo_id", title="RepoID"),
                TableColumn(
                    field="software_name",
                    title="OSS",
                    formatter=HTMLTemplateFormatter(template=template_str)),
                TableColumn(field="featcnt",
                            title="FeatCount",
                            formatter=NumberFormatter(format="0,000,000")),
                TableColumn(field="featfreq",
                            title="FeatFreq",
                            formatter=NumberFormatter(format="0,000,000")),
                TableColumn(field="version", title="Version"),
                TableColumn(field="decision",
                            title="Decision",
                            editor=decision_editor),
                TableColumn(field="status",
                            title="Status",
                            editor=status_editor),
                TableColumn(field="comment", title="Comment"),
                TableColumn(field="path", title="Path"),
            ]

        # source is the displayed table, and can be modified by user
        # original_source is the original data, it is the base, and can only be modified by the program
        self.source = ColumnDataSource(self._data)
        self.original_source = ColumnDataSource(self._data)
        self.data_table = DataTable(source=self.source,
                                    columns=columns,
                                    width=2000,
                                    height=2000,
                                    editable=True,
                                    sortable=True)  # Disable sortable for now!

        # selector or filters
        # reference link for callback: https://gist.github.com/dennisobrien/450d7da20daaba6d39d0
        min_matching_score_slider = Slider(start=0,
                                           end=2,
                                           value=0.3,
                                           step=.01,
                                           title="Minimum Matching Score")
        max_matching_score_slider = Slider(start=0,
                                           end=2,
                                           value=0.7,
                                           step=.01,
                                           title="Maximum Matching Score")
        featfreq_slider = Slider(start=0,
                                 end=10000,
                                 value=0,
                                 step=1,
                                 title="Minimum Matching Num of Features")
        featcnt_slider = Slider(start=0,
                                end=10000,
                                value=50,
                                step=1,
                                title="Minimum Feature Count is OSS")
        kind_select = Select(value="All", options=["All", "Java", "Native"])
        file_select = Select(value="Name", options=["Name", "MD5", "Path"])
        search_input = TextInput(value=None,
                                 title="Enter library to search",
                                 callback=None)
        search_button = Button(label="Search", button_type="success")

        download_callback_code = """
        var data = source.get('data');
        var filetext = 'Id,File Name,Matching Score,Normalized Matching Score,Repo ID,Software Name,Feature Count,Feature Freq.,Version,Decision,Status,Comment,File Path\\n';

        var order = ['myindex', 'name', 'score', 'normscore', 'repo_id', 'software_name', 'featcnt', 'featfreq', 'version', 'decision', 'status', 'comment', 'path'];

        for (var i = 0; i < data['path'].length; ++i) {
            var currRow = [];
            for (var item in order) {
                key = order[item]
                currRow.push(data[key][i]);
            }
            var joined = currRow.join().concat('\\n');
            filetext = filetext.concat(joined);
        }

        var filename = 'violations.csv';
        var blob = new Blob([filetext], { type: 'text/csv;charset=utf-8;' });
        
        //addresses IE
        if (navigator.msSaveBlob) {
            //navigator.msSaveBlob(blob, filename);
        }
        else {
            var link = document.createElement("a");
            link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.download = filename;
            link.target = "_blank";
            link.style.visibility = 'hidden';
            link.dispatchEvent(new MouseEvent('click'));
        }
        """

        # enable downloading of results as a csv file
        download_button = Button(label="Download", button_type="success")
        download_button.callback = CustomJS(args=dict(source=self.source),
                                            code=download_callback_code)

        # enable comparison of selected rows
        compare_button = Button(label="Compare", button_type="success")
        compare_button.on_click(self.compare_callback)

        # update on change
        #controls = [min_matching_score_slider, max_matching_score_slider, featfreq_slider, \
        #            featcnt_slider, kind_select, file_select, button]
        #for item in controls:
        #    item.on_change('value', lambda attr, old, new: self.update_source(item))

        combined_callback_code = """
        var data = source.get('data');
        var original_data = original_source.get('data');
        var min_score = min_matching_score_slider.get('value');
        var max_score = max_matching_score_slider.get('value');
        var search_input = search_input.get('value');
        var min_featfreq = featfreq_slider.get('value');
        var min_featcnt = featcnt_slider.get('value');
        var kind = kind_select.get('value');
        console.log("min score: " + min_score + ", max score: " + max_score + ", min_featfreq: " + min_featfreq + ", min_featcnt" + min_featcnt + ", kind" + kind);
        var java_suffix = ".dex";
        var native_suffix = ".so";

        console.log("searchinput: " + search_input);
        var re;
        if (search_input) {
            re = new RegExp(search_input);
        } else {
            re = new RegExp(".*");
        }

        for (var key in original_data) {
            data[key] = [];
            for (var i = 0; i < original_data['path'].length; ++i) {
                if ((original_data['normscore'][i] >= min_score) && (original_data['normscore'][i] <= max_score) && (original_data['featfreq'][i] >= min_featfreq) &&
                    (original_data['featcnt'][i] >= min_featcnt)) {
                    // filter by java
                    if (kind == "Java" && original_data['path'][i].indexOf(java_suffix, original_data['path'][i].length - java_suffix.length) === -1)
                        continue;
                    // filter by native
                    if (kind == "Native" && original_data['path'][i].indexOf(native_suffix, original_data['path'][i].length - native_suffix.length) === -1)
                        continue;
                    // filter by search regex
                    if (!re.test(original_data['name'][i])) {
                        console.log("mismatch: " + original_data['name'][i]);
                        continue;
                    }
                    // this row is the expected kind
                    data[key].push(original_data[key][i]);
                }
            }
        }
        source.trigger('change');
        target.trigger('change');
        """
        generic_callback = CustomJS(args=dict(
            source=self.source,
            original_source=self.original_source,
            search_input=search_input,
            max_matching_score_slider=max_matching_score_slider,
            min_matching_score_slider=min_matching_score_slider,
            featfreq_slider=featfreq_slider,
            featcnt_slider=featcnt_slider,
            kind_select=kind_select,
            target=self.data_table),
                                    code=combined_callback_code)
        min_matching_score_slider.callback = generic_callback
        max_matching_score_slider.callback = generic_callback
        featfreq_slider.callback = generic_callback
        featcnt_slider.callback = generic_callback
        search_button.callback = generic_callback
        kind_select.callback = generic_callback

        # install callback when a row gets selected
        self.source.on_change('selected', self.selected_callback)

        ###########################################################
        # Main
        ###########################################################
        controls = [min_matching_score_slider, max_matching_score_slider, featfreq_slider, \
                    featcnt_slider, kind_select, file_select, search_input, search_button, \
                    download_button, compare_button]
        plots_box = widgetbox(*controls, width=800, sizing_mode="fixed")
        layout = column(plots_box, self.data_table, sizing_mode="fixed")

        return layout
コード例 #4
0
fpa_experts = ['Duan', 'Fanning', 'Fagrelius', 'Schubnell', 'Silber',
               'Poppett', 'Kai']
pcm = pm.PosCalManager()
pi = pm.get_positioner_index()
source = ColumnDataSource(data=pcm.table)
source.selected.indices = [pcm.i_selected]  # ['1d']['indices'] = [i_selected]
title = Div(text='''
<font size="4">Positioner Calibrations</font> (some columns editable)''',
            width=500)
columns = [TableColumn(field='UTC', title='UTC', width=160),
           TableColumn(field='expid', title='expid', width=50),
           TableColumn(field='test name', title='test name', width=260),
           TableColumn(field='exptime', title='exptime/s', width=60,
                       editor=NumberEditor()),
           TableColumn(field='dome', title='dome', width=50,
                       editor=SelectEditor(options=['open', 'closed', '?'])),
           TableColumn(field='zenith angle', title='zenith angle', width=69,
                       editor=IntEditor()),
           TableColumn(field='tracking', title='tracking', width=50,
                       editor=SelectEditor(options=['on', 'off', '?'])),
           TableColumn(field='T ambient', title='T ambient/°C', width=75,
                       editor=NumberEditor()),
           TableColumn(field='T mirror', title='T mirror/°C', width=65,
                       editor=NumberEditor()),
           TableColumn(field='PMTC', title='PMTC', width=50,
                       editor=SelectEditor(options=['on', 'off', '?'])),
           TableColumn(field='PCVF', title='PCVF', width=50,
                       editor=SelectEditor(options=['on', 'off', '?'])),
           TableColumn(field='dome louvers', title='dome louvers', width=75,
                       editor=SelectEditor(options=['on', 'off', '?'])),
           TableColumn(field='dome fans', title='dome fans', width=60,