Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Trinket Compare #113

Draft
wants to merge 42 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a9d3c5e
adds trinket compare feature
Nov 21, 2023
f159421
rm whitespace
Nov 21, 2023
c908de2
Submenu styling
Nov 26, 2023
62f0a19
adds item ids
Mar 10, 2024
3579dc4
caches trinket data for trinket_compare, updates fetching to be prima…
Apr 8, 2024
8ad944c
Merge branch 'Bloodmallet:develop' into develop
Apr 8, 2024
f023d00
rm most fetching/processing from general.py
Apr 9, 2024
ec12b74
Merge branch 'develop' of github.com:Ellimistdev/bloodmallet_web_fron…
Apr 9, 2024
8aa277b
cleans up general.py
Apr 9, 2024
429c44f
lint
Apr 9, 2024
5fd1448
some organization
Apr 9, 2024
97796c5
linting
Apr 9, 2024
da89ca4
Aligns trinket nav with displayed chart, redraws chart on nav selecti…
Apr 10, 2024
c84c47e
update for s4
Jun 22, 2024
700cd33
Merge remote-tracking branch 'upstream/develop' into develop
Ellimistdev Jun 22, 2024
f4528e0
adds trinket compare feature
Nov 21, 2023
6cedf97
rm whitespace
Nov 21, 2023
8295373
Submenu styling
Nov 26, 2023
89bbed1
adds item ids
Mar 10, 2024
205988a
caches trinket data for trinket_compare, updates fetching to be prima…
Apr 8, 2024
2651abc
rm most fetching/processing from general.py
Apr 9, 2024
ac9bd44
cleans up general.py
Apr 9, 2024
41f50e4
lint
Apr 9, 2024
667fd3f
some organization
Apr 9, 2024
7d76748
linting
Apr 9, 2024
b98c851
Aligns trinket nav with displayed chart, redraws chart on nav selecti…
Apr 10, 2024
8e08d36
update for s4
Jun 22, 2024
56acb03
Merge branch 'develop' of github.com:Ellimistdev/bloodmallet_web_fron…
Ellimistdev Sep 8, 2024
69670da
Merge pull request #2 from Bloodmallet/develop
Ellimistdev Oct 29, 2024
e8e6a25
Merge remote-tracking branch 'upstream/develop' into develop
Ellimistdev Feb 20, 2025
25047a9
fix merge
Ellimistdev Feb 20, 2025
f18b158
Rollup changes for trinket_compare
Ellimistdev Feb 23, 2025
f29084c
Fixes nav and trinket population. pulls in new data
Ellimistdev Feb 28, 2025
99204c7
linting
Ellimistdev Feb 28, 2025
6c67a37
ws
Ellimistdev Feb 28, 2025
6a77f0a
Fixes trinket compare localization. Adds bm-utils.js, comments.
Ellimistdev Feb 28, 2025
75c568a
linting
Ellimistdev Feb 28, 2025
487f1cb
Moves Fight style dictionary to bmutils.
Ellimistdev Feb 28, 2025
5f2f595
reverts bm_chart_import changes
Ellimistdev Feb 28, 2025
6afc594
ws
Ellimistdev Feb 28, 2025
dc093bc
rm debug logging
Ellimistdev Feb 28, 2025
713a3b4
rm comment
Ellimistdev Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 100 additions & 50 deletions general_website/static/general_website/js/bloodmallet_chart_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ function bloodmallet_chart_import() {

const debug = false;

const path_to_data = "https://bloodmallet.com/chart/get/";
const host = "https://bloodmallet.com";
const localhost = "http://127.0.0.1:8000";
const path_to_data = "/chart/get/";

const language_table = {
"cn": "cn_CN",
Expand Down Expand Up @@ -204,6 +206,8 @@ function bloodmallet_chart_import() {
chart_id: undefined,
wow_class: undefined,
wow_spec: undefined,
item_name: undefined,
item_level: undefined,
data_type: default_data_type,
fight_style: default_fight_style,
covenant: default_covenant,
Expand Down Expand Up @@ -299,16 +303,21 @@ function bloodmallet_chart_import() {
// preparing necessary input to load data
let requirements = true;
if (!html_element.getAttribute("data-chart-id")) {
if (!html_element.getAttribute("data-wow-class")) {
console.error("Required 'data-chart-id' or 'data-wow-class' attribute wasn't found in " + html_id + ".")
requirements = false;
}
state.wow_class = html_element.getAttribute("data-wow-class");
if (!html_element.getAttribute("data-wow-spec")) {
console.error("Required 'data-chart-id' or 'data-wow-spec' attribute wasn't found in " + html_id + ".")
requirements = false;
if (!html_element.getAttribute("data-item-name")) {
if (!html_element.getAttribute("data-wow-class")) {
console.error("Required 'data-chart-id' or 'data-wow-class' attribute wasn't found in " + html_id + ".")
requirements = false;
}
state.wow_class = html_element.getAttribute("data-wow-class");
if (!html_element.getAttribute("data-wow-spec")) {
console.error("Required 'data-chart-id' or 'data-wow-spec' attribute wasn't found in " + html_id + ".")
requirements = false;
}
state.wow_spec = html_element.getAttribute("data-wow-spec");
} else {
state.item_name = html_element.getAttribute("data-item-name");
state.item_level = html_element.getAttribute("data-item-level");
}
state.wow_spec = html_element.getAttribute("data-wow-spec");
} else {
state.chart_id = html_element.getAttribute("data-chart-id");
}
Expand Down Expand Up @@ -359,6 +368,8 @@ function bloodmallet_chart_import() {
let chart_id = state.chart_id;
let data_type = state.data_type;
let fight_style = state.fight_style;
let item_name = state.item_name;
let item_level = state.item_level;
let wow_class = state.wow_class;
let wow_spec = state.wow_spec;

Expand All @@ -373,19 +384,15 @@ function bloodmallet_chart_import() {
console.log(error);
}
}
const data_group = (data_type === 'trinket_compare') ? 'trinkets' : data_type;
const data_name = [item_name, item_level, fight_style, wow_class, wow_spec]
.filter(Boolean)
.join('/');
// local dev differentiation since no local db
// can likely be removed in prod
const base_url = (wow_class && wow_spec) ? host : localhost;

let data_group = data_type;

let data_name = fight_style;
data_name += "/" + wow_class;
data_name += "/" + wow_spec;

let url = "";
if (chart_id) {
url = path_to_data + chart_id;
} else {
url = path_to_data + data_group + "/" + data_name;
}
const url = `${base_url}${path_to_data}${chart_id || data_group}${data_name ? `/${data_name}` : ''}`.replace(/\/+$/, '');

let request = new XMLHttpRequest();
if (debug) {
Expand Down Expand Up @@ -436,7 +443,9 @@ function bloodmallet_chart_import() {
try {
spec_data = get_data_from_state(state);
} catch (error) {
if (count < 30) {
// fetching trinket data via exposed endpoints is inefficient,
// using db directly should be able to get massively better performance
if (count < 100) {
setTimeout(update_chart, 200, state, html_element, chart, count + 1);
}
return;
Expand All @@ -454,9 +463,9 @@ function bloodmallet_chart_import() {
if (spec_data["error"] === true || spec_data["status"] === "error") {
return simulation_error(html_element, spec_data);
} else {
wow_class = spec_data['simc_settings']['class'];
wow_spec = spec_data['simc_settings']['spec'];
fight_style = spec_data['simc_settings']['fight_style'];
wow_class = spec_data?.simc_settings?.class;
wow_spec = spec_data?.simc_settings?.spec;
fight_style = spec_data?.simc_settings?.fight_style;
}
state.data_type = data_type = spec_data["data_type"];

Expand Down Expand Up @@ -490,7 +499,7 @@ function bloodmallet_chart_import() {
} else {
dps_ordered_keys = Object.keys(data["data"]);
}
if (["races", "talents", "soulbinds", "tier_set", "windfury_totem", "power_infusion"].includes(data_type)) {
if (["races", "talents", "soulbinds", "tier_set", "windfury_totem", "power_infusion", "trinket_compare"].includes(data_type)) {
baseline_dps = 0;
} else if (["legendaries", "soulbind_nodes", "covenants", "domination_shards"].includes(data_type)) {
baseline_dps = data["data"]["baseline"];
Expand Down Expand Up @@ -542,9 +551,11 @@ function bloodmallet_chart_import() {
simulated_steps = simulated_steps.filter(element => ilevels.indexOf(element.toString()) === -1);
}
// filter by availability of simulated_steps
dps_ordered_keys = dps_ordered_keys.filter(element =>
simulated_steps.some(step => data["data"][element][step] !== undefined)
);
if (simulated_steps) {
dps_ordered_keys = dps_ordered_keys.filter(element =>
simulated_steps.some(step => data["data"][element][step] !== undefined)
);
}
// Active - Passive
if (state.html_element.dataset.filterActivePassive !== undefined) {
const active_passives = state.html_element.dataset.filterActivePassive.split(";");
Expand All @@ -566,21 +577,23 @@ function bloodmallet_chart_import() {
dps_ordered_keys = dps_ordered_keys.filter(element => sources.indexOf(data["data_sources"][element]) === -1);
}

// resort dps_ordered_keys
let tmp_list = [];
for (let trinket of dps_ordered_keys) {
let dps = undefined;
for (let step of simulated_steps) {
if (dps === undefined && data["data"][trinket][step] !== undefined) {
dps = data["data"][trinket][step];
} else if (data["data"][trinket][step] !== undefined && data["data"][trinket][step] > dps) {
dps = data["data"][trinket][step];
if ("trinket_compare" !== data_type) {
// resort dps_ordered_keys
let tmp_list = [];
for (let trinket of dps_ordered_keys) {
let dps = undefined;
for (let step of simulated_steps) {
if (dps === undefined && data["data"][trinket][step] !== undefined) {
dps = data["data"][trinket][step];
} else if (data["data"][trinket][step] !== undefined && data["data"][trinket][step] > dps) {
dps = data["data"][trinket][step];
}
}
tmp_list.push([trinket, dps]);
}
tmp_list.push([trinket, dps]);
tmp_list.sort((trinket1, trinket2) => trinket2[1] - trinket1[1]);
dps_ordered_keys = tmp_list.map(element => element[0]);
}
tmp_list.sort((trinket1, trinket2) => trinket2[1] - trinket1[1]);
dps_ordered_keys = tmp_list.map(element => element[0]);
}

let subtitle = data["subtitle"];
Expand Down Expand Up @@ -781,8 +794,9 @@ function bloodmallet_chart_import() {
color: covenants[mapper[special_case.slice(1, special_case.length - 1)]]["color"]
}, false);
}
} else if (["windfury_totem", "power_infusion"].includes(data_type)) {
} else if (["windfury_totem", "power_infusion", "trinket_compare"].includes(data_type)) {
let dps_array = [];
let sortedKeys = [];

let melee_spec_color_map = {
"Blood Death Knight": "#c41f3b",
Expand All @@ -794,7 +808,7 @@ function bloodmallet_chart_import() {
"Feral Druid": "#ff7d0a",
"Guardian Druid": "#ff7d0a",
"Devastation Evoker": "#33937F",
"Beast_Mastery Hunter": "#abd473",
"Beast Mastery Hunter": "#abd473",
"Marksmanship Hunter": "#abd473",
"Survival Hunter": "#abd473",
"Arcane Mage": "#69ccf0",
Expand All @@ -818,17 +832,53 @@ function bloodmallet_chart_import() {
"Protection Warrior": "#c79c6e",
}

for (let dps_key of dps_ordered_keys) {
let tmp_baseline_dps = data["data"]["{" + dps_key + "}"];
let dps_key_values = data["data"][dps_key] - tmp_baseline_dps;
dps_array.push({ "y": get_styled_value(state, dps_key_values, tmp_baseline_dps), "color": melee_spec_color_map[dps_key] });
if (["trinket_compare"].includes(data_type)) {
let comparative_dps = {};
for (let dps_key of dps_ordered_keys) {
let tmp_baseline_dps = data["data"]["baseline"][dps_key];
let dps_key_values = data["data"][dps_key] - tmp_baseline_dps;
comparative_dps[dps_key] = {
"y": get_styled_value(state, dps_key_values, tmp_baseline_dps),
"color": melee_spec_color_map[dps_key]
};
}

// Extract keys and sort them
sortedKeys = Object.keys(comparative_dps)
.sort((a, b) => comparative_dps[b].y - comparative_dps[a].y);

// Remove 'baseline' key if it exists
sortedKeys = sortedKeys.filter(key => key !== 'baseline');

for (let key of sortedKeys) {
dps_array.push(comparative_dps[key]);
}
} else {
for (let dps_key of dps_ordered_keys) {
let tmp_baseline_dps = data["data"]["{" + dps_key + "}"];
let dps_key_values = data["data"][dps_key] - tmp_baseline_dps;
dps_array.push({ "y": get_styled_value(state, dps_key_values, tmp_baseline_dps), "color": melee_spec_color_map[dps_key] });
}
}

chart.addSeries({
data: dps_array,
name: snake_case_to_title(data_type),
showInLegend: false,
}, false);

if (["trinket_compare"].includes(data_type)) {
// Update the x-axis categories
if (chart_engine == "highcharts") {
chart.update({
xAxis: {
categories: sortedKeys
}
}, false);
} else if (chart_engine == "highcharts_old") {
chart.xAxis[0].setCategories(sortedKeys, false);
}
}
} else if (["domination_shards"].includes(data_type)) {
for (let shard_type of Object.keys(domination_shard_colours)) {

Expand Down Expand Up @@ -2268,8 +2318,8 @@ function bloodmallet_chart_import() {

// redo simc hash properly
let simc_link = document.createElement("a");
simc_link.href = "https://github.com/simulationcraft/simc/commit/" + data["simc_settings"]["simc_hash"];
simc_link.innerText = data["simc_settings"]["simc_hash"].substring(0, 7);
simc_link.href = "https://github.com/simulationcraft/simc/commit/" + data?.simc_settings?.simc_hash;
simc_link.innerText = data?.simc_settings?.simc_hash?.substring(0, 7);
let simc_hash = document.getElementById("c_simc_hash")
if (simc_hash !== undefined && simc_hash !== null) {
simc_hash.innerText = "";
Expand Down
Loading