Skip to content

Commit

Permalink
Add option to remove datapoints by SHIFT clicking squares and dots in…
Browse files Browse the repository at this point in the history
… the Gantt chart
  • Loading branch information
GJFR committed Nov 26, 2024
1 parent 1272591 commit 7572c70
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 10 deletions.
5 changes: 5 additions & 0 deletions bci/database/mongo/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ def get_documents_for_plotting(self, params: PlotParameters, releases: bool = Fa
)
return list(docs)

def remove_datapoint(self, params: TestParameters) -> None:
collection = self.get_collection(params.database_collection)
query = self.__to_query(params)
collection.delete_one(query)

def get_info(self) -> dict:
if self.client and self.client.address:
return {'type': 'mongo', 'host': self.client.address[0], 'connected': True}
Expand Down
10 changes: 10 additions & 0 deletions bci/evaluations/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ class TestParameters:
def create_test_result_with(self, browser_version: str, binary_origin: str, data: dict, dirty: bool) -> TestResult:
return TestResult(self, browser_version, binary_origin, data, dirty)

@staticmethod
def from_dict(data) -> Optional[TestParameters]:
if data is None:
return None
browser_configuration = BrowserConfiguration.from_dict(data)
evaluation_configuration = EvaluationConfiguration.from_dict(data)
state = State.from_dict(data)
mech_group = data['mech_group']
database_collection = data['db_collection']
return TestParameters(browser_configuration, evaluation_configuration, state, mech_group, database_collection)

@dataclass(frozen=True)
class TestResult:
Expand Down
5 changes: 5 additions & 0 deletions bci/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bci.evaluations.logic import (
DatabaseParameters,
EvaluationParameters,
TestParameters,
)
from bci.evaluations.outcome_checker import OutcomeChecker
from bci.search_strategy.bgb_search import BiggestGapBisectionSearch
Expand Down Expand Up @@ -168,6 +169,10 @@ def push_info(self, ws, *args) -> None:
update['state'] = self.state
Clients.push_info(ws, update)

def remove_datapoint(self, params: TestParameters) -> None:
MongoDB().remove_datapoint(params)
Clients.push_results_to_all()

def __update_state(self, **kwargs) -> None:
for key, value in kwargs.items():
self.state[key] = value
Expand Down
14 changes: 14 additions & 0 deletions bci/web/blueprints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,17 @@ def create_experiment(project: str):
'status': 'NOK',
'msg': 'Could not create experiment'
}


@api.route('/data/remove/', methods=['POST'])
def remove_datapoint():
if (params := application_logic.TestParameters.from_dict(request.json)) is None:
return {
'status': 'NOK',
'msg': "No parameters found"
}
__get_main().remove_datapoint(params)
return {
'status': 'OK'
}

6 changes: 3 additions & 3 deletions bci/web/vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export default {
}
this.propagate_new_params();
});
websocket.addEventListener("message", () => {
const data = JSON.parse(event.data);
websocket.addEventListener("message", (e) => {
const data = JSON.parse(e.data);
if (data.hasOwnProperty("update")) {
if (data.update.hasOwnProperty("plot_data")) {
const revision_data = data.update.plot_data.revision_data;
Expand Down Expand Up @@ -553,7 +553,7 @@ export default {
</ul>
</div>
</div>
<gantt ref="gantt"></gantt>
<gantt ref="gantt" :eval_params="this.eval_params"></gantt>
</div>
</div>

Expand Down
65 changes: 59 additions & 6 deletions bci/web/vue/src/components/gantt.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<script>
import axios from 'axios'
export default {
props: {
eval_params: Object,
},
data() {
return {
browser_name: null,
poc: null,
project: null,
plot: null,
revision_source: {
data: [],
Expand All @@ -18,6 +24,17 @@ export default {
methods: {
init_plot() {
console.log("Initializing Gantt chart...");
document.addEventListener("keydown", (e) => {
if (e.shiftKey) {
this.shift_down = true;
}
});
document.addEventListener("keyup", (e) => {
if (e.shiftKey) {
this.shift_down = false;
}
});
if (this.revision_source.length === 0 || this.version_source.length === 0) {
this.x_min = 1;
Expand Down Expand Up @@ -91,11 +108,29 @@ export default {
if (urlTemplate) {
const tapTool = new Bokeh.TapTool({
behavior: 'select',
callback: () => {
if (this.revision_source.selected.indices.length > 0) {
let index = this.revision_source.selected.indices[0];
let revision_number = this.revision_source.data.revision_number[index];
window.open(urlTemplate + revision_number);
callback: (e) => {
var index;
if ((index = this.revision_source.selected.indices[0]) !== undefined) {
var revision_number = this.revision_source.data.revision_number[index];
var browser_version = this.revision_source.data.browser_version[index];
var type = "revision";
} else if ((index = this.version_source.selected.indices[0]) !== undefined) {
var revision_number = this.version_source.data.revision_number[index];
var browser_version = this.version_source.data.browser_version[index];
var type = "version";
} else {
console.log("Nothing interesting was selected...");
return;
}
if (this.shift_down) {
// Ask to remove datapoint
this.remove_datapoint(revision_number, browser_version, type);
} else {
// Open revision page
if (this.revision_source.selected.indices.length > 0) {
window.open(urlTemplate + revision_number);
}
}
this.revision_source.selected.indices = [];
this.version_source.selected.indices = [];
Expand All @@ -122,13 +157,15 @@ export default {
Bokeh.Plotting.show(this.plot, document.getElementById('gantt'));
console.log("Gantt chart initialized!");
},
update_plot(browser_name, revision_data, version_data) {
update_plot(browser_name, revision_data, version_data, project, poc) {
if (revision_data === null && version_data === null) {
return;
}
let init_required = this.revision_source === null || this.browser_name !== browser_name;
this.browser_name = browser_name;
this.project = project;
this.poc = poc;
if (init_required) {
this.revision_source = new Bokeh.ColumnDataSource({ data: revision_data });;
Expand Down Expand Up @@ -161,6 +198,22 @@ export default {
}
}
},
remove_datapoint(revision_number, browser_version, type) {
console.log("Removing datapoint ", revision_number, type);
const path = "/api/data/remove/"
var params = this.eval_params
params['type'] = type
params["revision_number"] = revision_number
params["major_version"] = browser_version
params["mech_group"] = params["plot_mech_group"]
axios.post(path, params)
.then((res) => {
})
.catch((error) => {
console.error(error);
});
},
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion bci/web/vue/src/components/section-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"results": {
"title": "Results",
"tooltip": "Choose an experiment from the dropdown menu to visualize its results in the Gantt chart below. Squares represent (approximate) release binaries, while dots represent revision binaries. Clicking on a dot will open the web page for the associated revision in the public browser repository."
"tooltip": "Choose an experiment from the dropdown menu to visualize its results in the Gantt chart below. Squares represent (approximate) release binaries, while dots represent revision binaries. Clicking on a dot will open the web page for the associated revision in the public browser repository. Holding shift while clicking on any dot or square will delete the particular result."
},
"search_strategy": {
"title": "Search strategy",
Expand Down

0 comments on commit 7572c70

Please sign in to comment.