mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
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:
parent
a5e5237b22
commit
a004356fdc
5 changed files with 162 additions and 105 deletions
|
@ -1414,6 +1414,15 @@ int MachineObject::get_bed_temperature_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()
|
||||
{
|
||||
if (can_abort()
|
||||
|
@ -2509,6 +2518,7 @@ bool MachineObject::is_in_printing_status(std::string status)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MachineObject::is_in_printing()
|
||||
{
|
||||
/* use print_status if print_status is valid */
|
||||
|
@ -4501,6 +4511,92 @@ void MachineObject::set_modeltask(BBLModelTask* 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)
|
||||
{
|
||||
if (!m_agent) return;
|
||||
|
|
|
@ -179,6 +179,15 @@ enum ManualPaCaliMethod {
|
|||
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 {
|
||||
public:
|
||||
AmsTray(std::string tray_id) {
|
||||
|
@ -761,15 +770,23 @@ public:
|
|||
std::string profile_id_;
|
||||
std::string task_id_;
|
||||
std::string subtask_id_;
|
||||
std::string last_subtask_id_;
|
||||
BBLSliceInfo* slice_info {nullptr};
|
||||
boost::thread* get_slice_info_thread { nullptr };
|
||||
boost::thread* get_model_task_thread { nullptr };
|
||||
|
||||
bool is_makeworld_subtask();
|
||||
|
||||
|
||||
int plate_index { -1 };
|
||||
std::string m_gcode_file;
|
||||
int gcode_file_prepare_percent = 0;
|
||||
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 subtask_name;
|
||||
bool is_sdcard_printing();
|
||||
|
@ -909,6 +926,7 @@ public:
|
|||
BBLSubTask* get_subtask();
|
||||
BBLModelTask* get_modeltask();
|
||||
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);
|
||||
|
||||
bool m_firmware_valid { false };
|
||||
|
|
|
@ -274,7 +274,6 @@ void MonitorPanel::on_update_all(wxMouseEvent &event)
|
|||
return;
|
||||
|
||||
set_default();
|
||||
m_status_info_panel->set_print_finish_status(false);
|
||||
update_all();
|
||||
|
||||
MachineObject *obj_ = dev->get_selected_machine();
|
||||
|
|
|
@ -1731,9 +1731,10 @@ void StatusPanel::init_scaled_buttons()
|
|||
}
|
||||
|
||||
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" ;
|
||||
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);
|
||||
int ret = m_score_dlg.ShowModal();
|
||||
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";
|
||||
m_score_data->rating_id = -1;
|
||||
m_project_task_panel->set_star_count_dirty(false);
|
||||
requested_rating_map.clear();
|
||||
m_print_finish = false;
|
||||
if (obj) obj->get_model_mall_result_need_retry = true;
|
||||
return;
|
||||
}
|
||||
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_project_task_panel->set_star_count(m_score_data->star_count);
|
||||
} else {
|
||||
//to do: if user has rated the model, show the comment on the dialog
|
||||
int star_count = 0;
|
||||
if (m_rating_result.contains("content"))
|
||||
star_count = m_project_task_panel->get_star_count_dirty() ? m_project_task_panel->get_star_count() : m_rating_result["score"].get<int>();
|
||||
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);
|
||||
int star_count = m_project_task_panel->get_star_count_dirty() ? m_project_task_panel->get_star_count() : obj->rating_info->start_count;
|
||||
bool success_print = obj->rating_info->success_printed;
|
||||
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,
|
||||
success_print, star_count);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": new data";
|
||||
|
||||
if (m_rating_result.contains("content")) {
|
||||
std::string comment = m_rating_result["content"].get<std::string>();
|
||||
if (!comment.empty()) {
|
||||
m_score_dlg.set_comment(comment);
|
||||
}
|
||||
}
|
||||
std::string comment = obj->rating_info->content;
|
||||
if (!comment.empty()) { m_score_dlg.set_comment(comment); }
|
||||
|
||||
if (m_rating_result.contains("images")) {
|
||||
std::vector<std::string> images_json_array;
|
||||
images_json_array = m_rating_result["images"].get<std::vector<std::string>>();
|
||||
m_score_dlg.set_cloud_bitmap(images_json_array);
|
||||
}
|
||||
images_json_array = obj->rating_info->image_url_paths;
|
||||
if (!images_json_array.empty()) m_score_dlg.set_cloud_bitmap(images_json_array);
|
||||
|
||||
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";
|
||||
m_score_data->rating_id = -1;
|
||||
m_project_task_panel->set_star_count_dirty(false);
|
||||
requested_rating_map.clear();
|
||||
m_print_finish = false;
|
||||
if (obj) obj->get_model_mall_result_need_retry = true;
|
||||
return;
|
||||
}
|
||||
if (m_score_data != nullptr) {
|
||||
|
@ -1799,8 +1787,11 @@ void StatusPanel::on_market_scoring(wxCommandEvent &event) {
|
|||
|
||||
void StatusPanel::on_market_retry(wxCommandEvent &event)
|
||||
{
|
||||
m_print_finish = false;
|
||||
requested_rating_map.clear();
|
||||
if (obj) {
|
||||
obj->get_model_mall_result_need_retry = true;
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(info)<< __FUNCTION__ << "retury failed";
|
||||
}
|
||||
}
|
||||
|
||||
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_task_id != obj->task_id_
|
||||
) {
|
||||
requested_rating_map.erase(last_task_id);
|
||||
last_subtask = obj->subtask_;
|
||||
last_profile_id = obj->profile_id_;
|
||||
last_task_id = obj->task_id_;
|
||||
request_model_info_flag = false;
|
||||
m_project_task_panel->set_star_count_dirty(false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -2739,7 +2730,6 @@ void StatusPanel::update_model_info()
|
|||
|
||||
|
||||
if (wxGetApp().getAgent() && obj) {
|
||||
|
||||
BBLSubTask* curr_task = obj->get_subtask();
|
||||
if (curr_task) {
|
||||
BBLModelTask* curr_model_task = obj->get_modeltask();
|
||||
|
@ -2808,90 +2798,51 @@ void StatusPanel::update_subtask(MachineObject *obj)
|
|||
else {
|
||||
m_project_task_panel->show_profile_info(false);
|
||||
}
|
||||
|
||||
update_basic_print_data(false);
|
||||
} else {
|
||||
if (obj->can_resume()) {
|
||||
m_project_task_panel->enable_pause_resume_button(true, "resume");
|
||||
|
||||
} else {
|
||||
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_pause_resume_button(false, "resume_disable");
|
||||
if (wxGetApp().has_model_mall()) {
|
||||
bool is_market_task = obj->get_modeltask() && obj->get_modeltask()->design_id > 0;
|
||||
if (is_market_task) {
|
||||
NetworkAgent *agent = wxGetApp().getAgent();
|
||||
if (agent && IsShownOnScreen()) {
|
||||
if (requested_rating_map.find(obj->subtask_id_) == requested_rating_map.end()) {
|
||||
requested_rating_map[obj->subtask_id_] = true;
|
||||
// is makeworld subtask
|
||||
if (wxGetApp().has_model_mall() && obj->is_makeworld_subtask()) {
|
||||
// has model mall rating result
|
||||
if (obj && obj->rating_info && obj->rating_info->request_successful) {
|
||||
m_project_task_panel->get_request_failed_panel()->Hide();
|
||||
int instance_id = obj->get_modeltask()->instance_id;
|
||||
std::string dev_id = obj->dev_id;
|
||||
boost::thread([this, agent, instance_id, dev_id] {
|
||||
try {
|
||||
std::string rating_result;
|
||||
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);
|
||||
BOOST_LOG_TRIVIAL(info) << "model mall result request successful";
|
||||
// has start count
|
||||
if (!m_project_task_panel->get_star_count_dirty()) {
|
||||
if (obj->rating_info->start_count > 0) {
|
||||
m_project_task_panel->set_star_count(obj->rating_info->start_count);
|
||||
m_project_task_panel->set_star_count_dirty(true);
|
||||
BOOST_LOG_TRIVIAL(info) << "Initialize scores";
|
||||
|
||||
if (0 != star_count) {
|
||||
m_project_task_panel->get_market_scoring_button()->Enable(true);
|
||||
m_project_task_panel->set_has_reted_text(true);
|
||||
} 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_model_mall_request_count = 0;
|
||||
} else {
|
||||
m_project_task_panel->get_request_failed_panel()->Show();
|
||||
m_project_task_panel->market_scoring_show();
|
||||
} else if (obj && obj->rating_info && !obj->rating_info->request_successful) {
|
||||
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 (...) {
|
||||
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
|
||||
} else {
|
||||
m_project_task_panel->market_scoring_hide();
|
||||
}
|
||||
} else { // model printing is not finished, hide scoring page
|
||||
m_project_task_panel->enable_abort_button(true);
|
||||
m_project_task_panel->market_scoring_hide();
|
||||
m_project_task_panel->get_request_failed_panel()->Hide();
|
||||
if (m_print_finish) {
|
||||
m_print_finish = false;
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
{
|
||||
if (obj) {
|
||||
|
|
|
@ -470,7 +470,6 @@ protected:
|
|||
int m_last_vcamera = -1;
|
||||
int m_model_mall_request_count = 0;
|
||||
bool m_is_load_with_temp = false;
|
||||
bool m_print_finish = false;
|
||||
json m_rating_result;
|
||||
|
||||
wxWebRequest web_request;
|
||||
|
@ -478,7 +477,6 @@ protected:
|
|||
bool nozzle_temp_input = false;
|
||||
bool cham_temp_input = false;
|
||||
bool request_model_info_flag = false;
|
||||
std::map<std::string, bool> requested_rating_map;
|
||||
int speed_lvl = 1; // 0 - 3
|
||||
int speed_lvl_timeout {0};
|
||||
boost::posix_time::ptime speed_dismiss_time;
|
||||
|
@ -627,7 +625,6 @@ public:
|
|||
|
||||
void set_default();
|
||||
void show_status(int status);
|
||||
void set_print_finish_status(bool is_finish);
|
||||
void set_hold_count(int& count);
|
||||
|
||||
void rescale_camera_icons();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue