ENH: [STUDIO-4579] limit request rating result count

Jira: 4579

Change-Id: Ifae6f50b46fc39254ce7c59d0deb1cf1e1940579
Signed-off-by: Stone Li <stone.li@bambulab.com>
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
This commit is contained in:
maosheng.wei 2023-09-27 11:54:29 +08:00 committed by Lane.Wei
parent a5e5237b22
commit a004356fdc
5 changed files with 162 additions and 105 deletions

View file

@ -1414,6 +1414,15 @@ int MachineObject::get_bed_temperature_limit()
return BED_TEMP_LIMIT; return BED_TEMP_LIMIT;
} }
bool MachineObject::is_makeworld_subtask()
{
if (model_task && model_task->design_id > 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " model task id: " << model_task->task_id << " is makeworld model";
return true;
}
return false;
}
bool MachineObject::is_sdcard_printing() bool MachineObject::is_sdcard_printing()
{ {
if (can_abort() if (can_abort()
@ -2509,6 +2518,7 @@ bool MachineObject::is_in_printing_status(std::string status)
return false; return false;
} }
bool MachineObject::is_in_printing() bool MachineObject::is_in_printing()
{ {
/* use print_status if print_status is valid */ /* use print_status if print_status is valid */
@ -4501,6 +4511,92 @@ void MachineObject::set_modeltask(BBLModelTask* task)
model_task = task; model_task = task;
} }
void MachineObject::update_model_task()
{
if (request_model_result > 10) return;
if (!m_agent) return;
if (!model_task) return;
if (!subtask_) return;
if (model_task->task_id != subtask_->task_id) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " times: " << request_model_result << " model_task_id !=subtask_id";
return;
}
if (model_task->instance_id <= 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " times: " << request_model_result << " instance_id <= 0";
return;
}
if ((!subtask_id_.empty() && last_subtask_id_ != subtask_id_) || get_model_mall_result_need_retry) {
if (!subtask_id_.empty() && last_subtask_id_ != subtask_id_) {
BOOST_LOG_TRIVIAL(info) << "update_model_task: last=" << last_subtask_id_ << ", curr=" << subtask_id_;
last_subtask_id_ = subtask_id_;
request_model_result = 0;
}
if (get_model_mall_result_need_retry) {
BOOST_LOG_TRIVIAL(info) << "need retry";
get_model_mall_result_need_retry = false;
}
} else {
BOOST_LOG_TRIVIAL(info) << "subtask_id_ no change and do not need retry";
return;
}
int curr_instance_id = model_task->instance_id;
if (rating_info) {
delete rating_info;
rating_info = nullptr;
}
get_model_task_thread = new boost::thread([this, curr_instance_id]{
try {
std::string rating_result;
unsigned int http_code = 404;
std::string http_error;
int res = -1;
res = m_agent->get_model_mall_rating_result(curr_instance_id, rating_result, http_code, http_error);
request_model_result++;
BOOST_LOG_TRIVIAL(info) << "request times: " << request_model_result << " http code: " << http_code;
rating_info = new RatingInfo();
if (0 == res && 200 == http_code) {
try {
json rating_json = json::parse(rating_result);
if (rating_json.contains("id")) {
rating_info->rating_id = rating_json["id"].get<unsigned int>();
//rating id is necessary info, so rating id must have
request_model_result = 0;
rating_info->request_successful = true;
BOOST_LOG_TRIVIAL(info) << "get rating id";
} else {
rating_info->request_successful = false;
BOOST_LOG_TRIVIAL(info) << "can not get rating id";
return;
}
if (rating_json.contains("score")) {
rating_info->start_count = rating_json["score"].get<int>();
}
if (rating_json.contains("content"))
rating_info->content = rating_json["content"].get<std::string>();
if (rating_json.contains("successPrinted"))
rating_info->success_printed = rating_json["successPrinted"].get<bool>();
if (rating_json.contains("images")) {
rating_info->image_url_paths = rating_json["images"].get<std::vector<std::string>>();
}
} catch (...) {
BOOST_LOG_TRIVIAL(info) << "parse model mall result json failed";
}
}
else {
rating_info->request_successful = false;
BOOST_LOG_TRIVIAL(info) << "model mall result request failed, request time: " << request_model_result << " http_code: " << http_code
<< " error msg: " << http_error;
return;
}
}
catch (...) {
BOOST_LOG_TRIVIAL(info) << "get mall model rating id failed and hide scoring page";
}
});
}
void MachineObject::update_slice_info(std::string project_id, std::string profile_id, std::string subtask_id, int plate_idx) void MachineObject::update_slice_info(std::string project_id, std::string profile_id, std::string subtask_id, int plate_idx)
{ {
if (!m_agent) return; if (!m_agent) return;

View file

@ -179,6 +179,15 @@ enum ManualPaCaliMethod {
PA_PATTERN, PA_PATTERN,
}; };
struct RatingInfo {
bool request_successful;
int rating_id;
int start_count;
bool success_printed;
std::string content;
std::vector<std::string> image_url_paths;
};
class AmsTray { class AmsTray {
public: public:
AmsTray(std::string tray_id) { AmsTray(std::string tray_id) {
@ -761,15 +770,23 @@ public:
std::string profile_id_; std::string profile_id_;
std::string task_id_; std::string task_id_;
std::string subtask_id_; std::string subtask_id_;
std::string last_subtask_id_;
BBLSliceInfo* slice_info {nullptr}; BBLSliceInfo* slice_info {nullptr};
boost::thread* get_slice_info_thread { nullptr }; boost::thread* get_slice_info_thread { nullptr };
boost::thread* get_model_task_thread { nullptr };
bool is_makeworld_subtask();
int plate_index { -1 }; int plate_index { -1 };
std::string m_gcode_file; std::string m_gcode_file;
int gcode_file_prepare_percent = 0; int gcode_file_prepare_percent = 0;
BBLSubTask* subtask_; BBLSubTask* subtask_;
BBLModelTask* model_task; BBLModelTask *model_task { nullptr };
RatingInfo* rating_info { nullptr };
int request_model_result = 0;
bool get_model_mall_result_need_retry = false;
std::string obj_subtask_id; // subtask_id == 0 for sdcard std::string obj_subtask_id; // subtask_id == 0 for sdcard
std::string subtask_name; std::string subtask_name;
bool is_sdcard_printing(); bool is_sdcard_printing();
@ -909,6 +926,7 @@ public:
BBLSubTask* get_subtask(); BBLSubTask* get_subtask();
BBLModelTask* get_modeltask(); BBLModelTask* get_modeltask();
void set_modeltask(BBLModelTask* task); void set_modeltask(BBLModelTask* task);
void update_model_task();
void update_slice_info(std::string project_id, std::string profile_id, std::string subtask_id, int plate_idx); void update_slice_info(std::string project_id, std::string profile_id, std::string subtask_id, int plate_idx);
bool m_firmware_valid { false }; bool m_firmware_valid { false };

View file

@ -274,7 +274,6 @@ void MonitorPanel::on_update_all(wxMouseEvent &event)
return; return;
set_default(); set_default();
m_status_info_panel->set_print_finish_status(false);
update_all(); update_all();
MachineObject *obj_ = dev->get_selected_machine(); MachineObject *obj_ = dev->get_selected_machine();

View file

@ -1731,9 +1731,10 @@ void StatusPanel::init_scaled_buttons()
} }
void StatusPanel::on_market_scoring(wxCommandEvent &event) { void StatusPanel::on_market_scoring(wxCommandEvent &event) {
if (obj && obj->get_modeltask() && obj->get_modeltask()->design_id > 0 && m_rating_result.contains("id")) { // model is mall model and has rating_id if (obj && obj->is_makeworld_subtask() && obj->rating_info && obj->rating_info->request_successful) { // model is mall model and has rating_id
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_market_scoring" ; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_market_scoring" ;
if (m_score_data && m_score_data->rating_id == m_rating_result["id"].get<unsigned int>()) { // current score data for model is same as mall model if (m_score_data && m_score_data->rating_id == obj->rating_info->rating_id) { // current score data for model is same as mall model
if (m_score_data->star_count != m_project_task_panel->get_star_count()) m_score_data->star_count = m_project_task_panel->get_star_count();
ScoreDialog m_score_dlg(this, m_score_data); ScoreDialog m_score_dlg(this, m_score_data);
int ret = m_score_dlg.ShowModal(); int ret = m_score_dlg.ShowModal();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data";
@ -1742,8 +1743,7 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data is upload"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": old data is upload";
m_score_data->rating_id = -1; m_score_data->rating_id = -1;
m_project_task_panel->set_star_count_dirty(false); m_project_task_panel->set_star_count_dirty(false);
requested_rating_map.clear(); if (obj) obj->get_model_mall_result_need_retry = true;
m_print_finish = false;
return; return;
} }
if (m_score_data != nullptr) { if (m_score_data != nullptr) {
@ -1753,29 +1753,18 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
m_score_data = new ScoreData(m_score_dlg.get_score_data()); // when user do not submit score, store the data for next opening the score dialog m_score_data = new ScoreData(m_score_dlg.get_score_data()); // when user do not submit score, store the data for next opening the score dialog
m_project_task_panel->set_star_count(m_score_data->star_count); m_project_task_panel->set_star_count(m_score_data->star_count);
} else { } else {
//to do: if user has rated the model, show the comment on the dialog int star_count = m_project_task_panel->get_star_count_dirty() ? m_project_task_panel->get_star_count() : obj->rating_info->start_count;
int star_count = 0; bool success_print = obj->rating_info->success_printed;
if (m_rating_result.contains("content")) ScoreDialog m_score_dlg(this, obj->get_modeltask()->design_id, obj->get_modeltask()->model_id, obj->get_modeltask()->profile_id, obj->rating_info->rating_id,
star_count = m_project_task_panel->get_star_count_dirty() ? m_project_task_panel->get_star_count() : m_rating_result["score"].get<int>(); success_print, star_count);
bool success_print = true;
if (m_rating_result.contains("successPrinted"))
success_print = m_rating_result["successPrinted"].get<bool>();
ScoreDialog m_score_dlg(this, obj->get_modeltask()->design_id, obj->get_modeltask()->model_id, obj->get_modeltask()->profile_id,
m_rating_result["id"].get<unsigned int>(), success_print, star_count);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": new data"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": new data";
if (m_rating_result.contains("content")) { std::string comment = obj->rating_info->content;
std::string comment = m_rating_result["content"].get<std::string>(); if (!comment.empty()) { m_score_dlg.set_comment(comment); }
if (!comment.empty()) {
m_score_dlg.set_comment(comment);
}
}
if (m_rating_result.contains("images")) {
std::vector<std::string> images_json_array; std::vector<std::string> images_json_array;
images_json_array = m_rating_result["images"].get<std::vector<std::string>>(); images_json_array = obj->rating_info->image_url_paths;
m_score_dlg.set_cloud_bitmap(images_json_array); if (!images_json_array.empty()) m_score_dlg.set_cloud_bitmap(images_json_array);
}
int ret = m_score_dlg.ShowModal(); int ret = m_score_dlg.ShowModal();
@ -1783,8 +1772,7 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": new data is upload"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": new data is upload";
m_score_data->rating_id = -1; m_score_data->rating_id = -1;
m_project_task_panel->set_star_count_dirty(false); m_project_task_panel->set_star_count_dirty(false);
requested_rating_map.clear(); if (obj) obj->get_model_mall_result_need_retry = true;
m_print_finish = false;
return; return;
} }
if (m_score_data != nullptr) { if (m_score_data != nullptr) {
@ -1799,8 +1787,11 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
void StatusPanel::on_market_retry(wxCommandEvent &event) void StatusPanel::on_market_retry(wxCommandEvent &event)
{ {
m_print_finish = false; if (obj) {
requested_rating_map.clear(); obj->get_model_mall_result_need_retry = true;
} else {
BOOST_LOG_TRIVIAL(info)<< __FUNCTION__ << "retury failed";
}
} }
void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event) void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event)
@ -1900,11 +1891,11 @@ bool StatusPanel::is_task_changed(MachineObject* obj)
|| last_profile_id != obj->profile_id_ || last_profile_id != obj->profile_id_
|| last_task_id != obj->task_id_ || last_task_id != obj->task_id_
) { ) {
requested_rating_map.erase(last_task_id);
last_subtask = obj->subtask_; last_subtask = obj->subtask_;
last_profile_id = obj->profile_id_; last_profile_id = obj->profile_id_;
last_task_id = obj->task_id_; last_task_id = obj->task_id_;
request_model_info_flag = false; request_model_info_flag = false;
m_project_task_panel->set_star_count_dirty(false);
return true; return true;
} }
return false; return false;
@ -2739,7 +2730,6 @@ void StatusPanel::update_model_info()
if (wxGetApp().getAgent() && obj) { if (wxGetApp().getAgent() && obj) {
BBLSubTask* curr_task = obj->get_subtask(); BBLSubTask* curr_task = obj->get_subtask();
if (curr_task) { if (curr_task) {
BBLModelTask* curr_model_task = obj->get_modeltask(); BBLModelTask* curr_model_task = obj->get_modeltask();
@ -2808,90 +2798,51 @@ void StatusPanel::update_subtask(MachineObject *obj)
else { else {
m_project_task_panel->show_profile_info(false); m_project_task_panel->show_profile_info(false);
} }
update_basic_print_data(false); update_basic_print_data(false);
} else { } else {
if (obj->can_resume()) { if (obj->can_resume()) {
m_project_task_panel->enable_pause_resume_button(true, "resume"); m_project_task_panel->enable_pause_resume_button(true, "resume");
} else { } else {
m_project_task_panel->enable_pause_resume_button(true, "pause"); m_project_task_panel->enable_pause_resume_button(true, "pause");
} }
if (obj->print_status == "FINISH") { if (obj->is_printing_finished()) {
obj->update_model_task();
m_project_task_panel->enable_abort_button(false); m_project_task_panel->enable_abort_button(false);
m_project_task_panel->enable_pause_resume_button(false, "resume_disable"); m_project_task_panel->enable_pause_resume_button(false, "resume_disable");
if (wxGetApp().has_model_mall()) { // is makeworld subtask
bool is_market_task = obj->get_modeltask() && obj->get_modeltask()->design_id > 0; if (wxGetApp().has_model_mall() && obj->is_makeworld_subtask()) {
if (is_market_task) { // has model mall rating result
NetworkAgent *agent = wxGetApp().getAgent(); if (obj && obj->rating_info && obj->rating_info->request_successful) {
if (agent && IsShownOnScreen()) {
if (requested_rating_map.find(obj->subtask_id_) == requested_rating_map.end()) {
requested_rating_map[obj->subtask_id_] = true;
m_project_task_panel->get_request_failed_panel()->Hide(); m_project_task_panel->get_request_failed_panel()->Hide();
int instance_id = obj->get_modeltask()->instance_id; BOOST_LOG_TRIVIAL(info) << "model mall result request successful";
std::string dev_id = obj->dev_id; // has start count
boost::thread([this, agent, instance_id, dev_id] { if (!m_project_task_panel->get_star_count_dirty()) {
try { if (obj->rating_info->start_count > 0) {
std::string rating_result; m_project_task_panel->set_star_count(obj->rating_info->start_count);
unsigned int http_code = 404;
std::string http_error;
int rating_id = -1;
int res = -1;
if (!this || !(this->obj) || this->obj->dev_id != dev_id) return;
if (m_model_mall_request_count > 20) return;
res = agent->get_model_mall_rating_result(instance_id, rating_result, http_code, http_error);
m_model_mall_request_count++;
BOOST_LOG_TRIVIAL(info) << "request times :" << m_model_mall_request_count;
if (0 == res) {
m_rating_result = json::parse(rating_result);
if (m_rating_result.contains("id")) {
rating_id = m_rating_result["id"].get<unsigned int>();
if (!this || !(this->obj) || this->obj->dev_id != dev_id) return;
m_project_task_panel->market_scoring_show();
BOOST_LOG_TRIVIAL(info) << "show scoring page";
// this mall model has score, user do not click star, Initialize scores only once per print startup program
if ((m_rating_result.contains("score"))) {
int star_count = m_rating_result["score"].get<int>();
m_project_task_panel->set_star_count(star_count);
m_project_task_panel->set_star_count_dirty(true); m_project_task_panel->set_star_count_dirty(true);
BOOST_LOG_TRIVIAL(info) << "Initialize scores"; BOOST_LOG_TRIVIAL(info) << "Initialize scores";
if (0 != star_count) {
m_project_task_panel->get_market_scoring_button()->Enable(true); m_project_task_panel->get_market_scoring_button()->Enable(true);
m_project_task_panel->set_has_reted_text(true); m_project_task_panel->set_has_reted_text(true);
} else { } else {
m_project_task_panel->set_star_count(0);
m_project_task_panel->set_star_count_dirty(false);
m_project_task_panel->get_market_scoring_button()->Enable(false);
m_project_task_panel->set_has_reted_text(false); m_project_task_panel->set_has_reted_text(false);
} }
} }
} m_project_task_panel->market_scoring_show();
m_model_mall_request_count = 0; } else if (obj && obj->rating_info && !obj->rating_info->request_successful) {
} else {
m_project_task_panel->get_request_failed_panel()->Show();
BOOST_LOG_TRIVIAL(info) << "model mall result request failed"; BOOST_LOG_TRIVIAL(info) << "model mall result request failed";
return; m_project_task_panel->get_market_retry_buttom()->Enable(!obj->get_model_mall_result_need_retry);
m_project_task_panel->get_request_failed_panel()->Show();
} }
} catch (...) { } else {
m_project_task_panel->market_scoring_hide();
BOOST_LOG_TRIVIAL(info) << "get mall model rating id failed and hide scoring page";
}
});
}
}
BOOST_LOG_TRIVIAL(info) << "SHOW_SCORE_BTU: design_id [" << obj->get_modeltask()->design_id << "] print_finish [" << m_print_finish << "]";
} else { // model is not mall model. hide scoring page
m_project_task_panel->market_scoring_hide();
}
} else { // have no model mall, hide scoring page
m_project_task_panel->market_scoring_hide(); m_project_task_panel->market_scoring_hide();
} }
} else { // model printing is not finished, hide scoring page } else { // model printing is not finished, hide scoring page
m_project_task_panel->enable_abort_button(true); m_project_task_panel->enable_abort_button(true);
m_project_task_panel->market_scoring_hide(); m_project_task_panel->market_scoring_hide();
m_project_task_panel->get_request_failed_panel()->Hide(); m_project_task_panel->get_request_failed_panel()->Hide();
if (m_print_finish) {
m_print_finish = false;
}
} }
// update printing stage // update printing stage
@ -3932,10 +3883,6 @@ void StatusPanel::show_status(int status)
} }
} }
void StatusPanel::set_print_finish_status(bool is_finish) {
m_print_finish = is_finish;
}
void StatusPanel::set_hold_count(int& count) void StatusPanel::set_hold_count(int& count)
{ {
if (obj) { if (obj) {

View file

@ -470,7 +470,6 @@ protected:
int m_last_vcamera = -1; int m_last_vcamera = -1;
int m_model_mall_request_count = 0; int m_model_mall_request_count = 0;
bool m_is_load_with_temp = false; bool m_is_load_with_temp = false;
bool m_print_finish = false;
json m_rating_result; json m_rating_result;
wxWebRequest web_request; wxWebRequest web_request;
@ -478,7 +477,6 @@ protected:
bool nozzle_temp_input = false; bool nozzle_temp_input = false;
bool cham_temp_input = false; bool cham_temp_input = false;
bool request_model_info_flag = false; bool request_model_info_flag = false;
std::map<std::string, bool> requested_rating_map;
int speed_lvl = 1; // 0 - 3 int speed_lvl = 1; // 0 - 3
int speed_lvl_timeout {0}; int speed_lvl_timeout {0};
boost::posix_time::ptime speed_dismiss_time; boost::posix_time::ptime speed_dismiss_time;
@ -627,7 +625,6 @@ public:
void set_default(); void set_default();
void show_status(int status); void show_status(int status);
void set_print_finish_status(bool is_finish);
void set_hold_count(int& count); void set_hold_count(int& count);
void rescale_camera_icons(); void rescale_camera_icons();