From a012774659caa286f3490d2524b98dc226cab214 Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sat, 21 Sep 2024 12:41:09 +0200 Subject: [PATCH 01/22] Pseudocode for idea --- RawDataProcessing/Modules/Submodules/utils.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/RawDataProcessing/Modules/Submodules/utils.py b/RawDataProcessing/Modules/Submodules/utils.py index af9bf3b..511ce9b 100644 --- a/RawDataProcessing/Modules/Submodules/utils.py +++ b/RawDataProcessing/Modules/Submodules/utils.py @@ -13,6 +13,7 @@ from typing import Tuple import pickle import numpy as np +from pybalmorel import IncFile #%% ------------------------------- ### ### 1. Conversion Functions ### @@ -101,3 +102,22 @@ def transform_xrdata(xarray: xr.Dataset, output = output.sel(selection) return output + +def create_geo_sets(geo_sets: Tuple[pd.DataFrame, dict], + prefix: Tuple[str, None] = None): + + IncFile(name='CCCRRRAAA') + if 'C' in geo_sets.keys(): + IncFile(name='CCC') + + if 'R' in geo_sets.keys(): + IncFile(name='CCCRRR') + IncFile(name='RRR') + + if 'A' in geo_sets.keys(): + IncFile(name='RRRAAA') + if prefix != None: + IncFile(name=f'{prefix}_AAA') + else: + IncFile(name='AAA') + \ No newline at end of file From 43ef1cfea4cfacefa87fcbb6374cdfe20bba5eb3 Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sat, 21 Sep 2024 12:53:06 +0200 Subject: [PATCH 02/22] First idea by chatgpt --- RawDataProcessing/Dashboard/index.html | 38 ++++++++++++++++++++++++++ RawDataProcessing/Dashboard/java.js | 23 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 RawDataProcessing/Dashboard/index.html create mode 100644 RawDataProcessing/Dashboard/java.js diff --git a/RawDataProcessing/Dashboard/index.html b/RawDataProcessing/Dashboard/index.html new file mode 100644 index 0000000..40f4611 --- /dev/null +++ b/RawDataProcessing/Dashboard/index.html @@ -0,0 +1,38 @@ + + + + + + Comma-separated Text Input + + + +

Enter Comma-Separated Text

+ + +
+ + + +
+ + + + +
+ + + + diff --git a/RawDataProcessing/Dashboard/java.js b/RawDataProcessing/Dashboard/java.js new file mode 100644 index 0000000..5f1f877 --- /dev/null +++ b/RawDataProcessing/Dashboard/java.js @@ -0,0 +1,23 @@ +function updateDisplay() { + // Get input values + const input1 = document.getElementById('input1').value; + const input2 = document.getElementById('input2').value; + const input3 = document.getElementById('input3').value; + + // Combine input values and split by commas + const textPieces = (input1 + ',' + input2 + ',' + input3).split(','); + + // Get the output section + const outputSection = document.getElementById('outputSection'); + outputSection.innerHTML = ''; // Clear existing content + + // Iterate over text pieces and create divs for each one + textPieces.forEach(text => { + if (text.trim()) { // Ensure there's text after trimming whitespace + const div = document.createElement('div'); + div.className = 'output-item'; + div.textContent = text.trim(); + outputSection.appendChild(div); + } + }); +} \ No newline at end of file From 92640ccc6bb79874bdb32d140837d880514d256e Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sat, 21 Sep 2024 13:04:04 +0200 Subject: [PATCH 03/22] Prepared for connection gui --- RawDataProcessing/Dashboard/index.html | 9 ++++-- RawDataProcessing/Dashboard/java.js | 41 +++++++++++++------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/RawDataProcessing/Dashboard/index.html b/RawDataProcessing/Dashboard/index.html index 40f4611..b26ad5f 100644 --- a/RawDataProcessing/Dashboard/index.html +++ b/RawDataProcessing/Dashboard/index.html @@ -6,11 +6,12 @@ Comma-separated Text Input -

Enter Comma-Separated Text

+
+

Enter Comma-Separated Text

+
+
+ +
- - - + + +
- -
-
-
+
+
+
+
+
From 671d5886923e76d8f1b71357da938e5c299c3ddd Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sat, 21 Sep 2024 13:39:07 +0200 Subject: [PATCH 05/22] Added click function --- RawDataProcessing/Dashboard/index.html | 6 ++++-- RawDataProcessing/Dashboard/java.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/RawDataProcessing/Dashboard/index.html b/RawDataProcessing/Dashboard/index.html index 246e58c..55f56fa 100644 --- a/RawDataProcessing/Dashboard/index.html +++ b/RawDataProcessing/Dashboard/index.html @@ -30,8 +30,10 @@ vertical-align: auto; margin-right: 10px; padding: 5px; - background-color: #f0f0f0; - border: 1px solid #ccc; + border: none; + } + .output-item:hover { + cursor: pointer; } diff --git a/RawDataProcessing/Dashboard/java.js b/RawDataProcessing/Dashboard/java.js index 57f7902..e8c9182 100644 --- a/RawDataProcessing/Dashboard/java.js +++ b/RawDataProcessing/Dashboard/java.js @@ -18,7 +18,19 @@ function updateDisplay() { div.className = 'output-item'; div.textContent = element.trim(); outputSection.appendChild(div); + div.style.backgroundColor = 'rgb(185, 185, 185)'; + + // Add function + div.addEventListener('click', click) } }); } +} + +function click() { + if (this.style.backgroundColor === 'rgb(185, 185, 185)') { + this.style.backgroundColor = 'rgb(153, 238, 154)'; + } else { + this.style.backgroundColor = 'rgb(185, 185, 185)'; + } } \ No newline at end of file From 5769f2e6598a0e0fbe74ab93651a8facddfe661a Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sat, 21 Sep 2024 14:12:12 +0200 Subject: [PATCH 06/22] Made category id's --- RawDataProcessing/Dashboard/index.html | 10 +++++----- RawDataProcessing/Dashboard/java.js | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/RawDataProcessing/Dashboard/index.html b/RawDataProcessing/Dashboard/index.html index 55f56fa..e4fa782 100644 --- a/RawDataProcessing/Dashboard/index.html +++ b/RawDataProcessing/Dashboard/index.html @@ -3,7 +3,7 @@ - Comma-separated Text Input + Geographical Set Generator - - - - -
-

Geographical Set Generator

-
-
- Write comma-separated names of countries, regions and areas in the inputs below.
- Connect countries to regions, and regions to areas by clicking the respective boxes below
-
- Beware not to resize the window after you have started connecting nodes, or the lines may look confusing.. Scrolling is ok however. -
-
-

Countries

-

Regions

-

Areas

-
-
- - - -
- - -
-
-
-
-
- - -
-

-
-
-
Press button to generate corresponding .inc files for CCC, RRR, AAA and connections -
-
-
-
- Save to folder:   - -
-
- -
- -
- - - - - diff --git a/RawDataProcessing/Dashboard/web/java.js b/RawDataProcessing/Dashboard/web/java.js deleted file mode 100644 index 3b50229..0000000 --- a/RawDataProcessing/Dashboard/web/java.js +++ /dev/null @@ -1,204 +0,0 @@ -// Initial values -let output_type = ['countries', 'regions', 'areas']; -let consoleOutput = document.getElementById('consoleOutput'); -let codeSnippet = document.getElementById('codeSnippet'); -window.to_be_connected = []; -window.connections = {}; -updateDisplay(); - -// Store the working directory in save to path -get_wkdir() - -// Resize the window and center -resizeAndCenterWindow(); - -function updateDisplay() { - // Clear - document.querySelectorAll('.connection-line').forEach(line => line.remove()); - window.connected_lines = { - 'countries' : {}, - 'regions' : {}, - 'areas' : {} - } - for (let i = 1; i <= 3; i++) { - // Get input value - let input = document.getElementById(`input${i}`).value; - - // Split by commas - let text = input.split(',') - - // Get the output section - let outputSection = document.getElementById(output_type[i-1]); - outputSection.innerHTML = ''; // Clear existing content - - // Iterate over text pieces and create divs for each one - text.forEach(element => { - if (element.trim()) { // Ensure there's text after trimming whitespace - const div = document.createElement('div'); - div.className = 'output-item'; - div.id = element.trim().replace(/\s+/g, '_'); - div.style.position = 'relative'; - div.style.zIndex = 10; - div.textContent = element.trim().replace(/\s+/g, '_'); - outputSection.appendChild(div); - div.style.backgroundColor = 'rgb(185, 185, 185)'; - - // Add function - div.addEventListener('click', click) - - // Store - window.connected_lines[output_type[i-1]][div.id] = []; - } - }); - - // Create connections - for (let node1 in window.connected_lines[output_type[i-1]]) { - if (window.connections.hasOwnProperty(node1)) { - let node1_array = window.connections[node1]; - node1_array.forEach(node2 => { - console.log(`Connection from ${node1} to ${node2}`); - window.connected_lines[output_type[i-1]][node1].push(node2); - drawConnection(node1, node2); - }) - } - } - } - codeSnippet.innerHTML = JSON.stringify(window.connected_lines, null, 2); -} - -// Add event listeners to inputs to trigger updateDisplay on every keystroke -for (let i = 1; i <= 3; i++) { - document.getElementById(`input${i}`).addEventListener('input', updateDisplay); -} - -function click() { - if (window.to_be_connected.length === 0) { - // If nothing selected, make this node active - this.style.backgroundColor = 'rgb(153, 238, 154)'; - window.to_be_connected = [this.id, this.parentNode.id]; - } else if (window.to_be_connected[0] === this.id) { - // If this node is selected, make it inactive - this.style.backgroundColor = 'rgb(185, 185, 185)'; - window.to_be_connected = []; - } else { - // Check if connection is valid - let firstId = document.getElementById(window.to_be_connected[0]); - let firstType = window.to_be_connected[1]; - let thisType = this.parentNode.id; - if (firstType === thisType) { - firstId.style.backgroundColor = 'rgb(185, 185, 185)'; - consoleOutput.innerHTML = `
Can't make connections between ${firstType} and ${thisType}
`; - consoleOutput.style.color = 'red'; - window.to_be_connected = []; - } else if ((firstType === 'countries' && thisType === 'areas') || (firstType === 'areas' && thisType === 'countries')) { - firstId.style.backgroundColor = 'rgb(185, 185, 185)'; - consoleOutput.innerHTML = `
Can't make connections between countries and areas
`; - consoleOutput.style.color = 'red'; - window.to_be_connected = []; - } else { - firstId.style.backgroundColor = 'rgb(185, 185, 185)'; - consoleOutput.innerHTML = `
Connection made!
`; - consoleOutput.style.color = 'green'; - - // Make correct direction - if ((firstType === 'countries' && thisType == 'regions') || (firstType === 'regions' && thisType == 'areas')) { - initiate_or_append(window.connections, firstId.id, this.id) - // console.log(window.connections); - } else { - initiate_or_append(window.connections, this.id, firstId.id) - // console.log(window.connections); - } - - window.to_be_connected = []; - updateDisplay(); - } - } -} - -function drawConnection(firstId, secondId) { - // Get divs - const firstDiv = document.getElementById(firstId); - const secondDiv = document.getElementById(secondId); - - // Insert a line between the two divs - const line = document.createElement('div'); - line.className = 'connection-line'; - document.body.appendChild(line); - - const updateLinePosition = () => { - const firstRect = firstDiv.getBoundingClientRect(); - const secondRect = secondDiv.getBoundingClientRect(); - const x1 = firstRect.left + firstRect.width / 2 ; - const y1 = firstRect.top + firstRect.height / 2 + window.scrollY; - const x2 = secondRect.left + secondRect.width / 2; - const y2 = secondRect.top + secondRect.height / 2 + window.scrollY; - - line.style.zIndex = 1; - line.style.position = 'absolute'; - line.style.width = `${Math.hypot(x2 - x1, y2 - y1)}px`; - line.style.height = '2px'; - line.style.backgroundColor = 'black'; - line.style.transformOrigin = '0 0'; - line.style.transform = `rotate(${Math.atan2(y2 - y1, x2 - x1)}rad)`; - line.style.left = `${x1}px`; - line.style.top = `${y1}px`; - }; - - updateLinePosition(); -} - -function move_lines(x, y) { - document.querySelectorAll('.connection-line').forEach(line => { - line.style.transform = `translate(${x}px, ${y}px)`; - }); -} - -window.addEventListener('scroll', updateLinePosition(window.scrollX, window.scrollY)); - -function initiate_or_append(dictionary, key, entry) { - if (dictionary.hasOwnProperty(key)) { - dictionary[key].push(entry); - } else { - dictionary[key] = [entry]; - } -} - - -function resizeAndCenterWindow() { - const screenWidth = window.screen.availWidth; - const screenHeight = window.screen.availHeight; - const newWidth = screenWidth * 0.5; - const newHeight = screenHeight * 0.6; - const newX = (screenWidth - newWidth) / 2; - const newY = (screenHeight - newHeight) / 2; - - window.resizeTo(newWidth, newHeight); - window.moveTo(newX, newY); -} - - -// Python functions -async function create_incfiles() { - let output = codeSnippet.innerHTML; - - let path_input = document.getElementById('save_to_path'); - let save_path = path_input.value; - - // Call Python - await eel.create_incfiles(output, save_path)(); - - // Output console - consoleOutput.innerHTML = `
.inc files succesfully generated to ${save_path}
`; - consoleOutput.style.color = 'green'; -} - - -async function get_wkdir() { - // Get working directory from python - let wkdir = await eel.get_wkdir()(); - - let path_input = document.getElementById('save_to_path'); - path_input.value = wkdir; - -} - diff --git a/RawDataProcessing/Dashboard/web/network.svg b/RawDataProcessing/Dashboard/web/network.svg deleted file mode 100644 index e560d6a..0000000 --- a/RawDataProcessing/Dashboard/web/network.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/environment.yaml b/environment.yaml index f9e99ac..fc08f5f 100644 --- a/environment.yaml +++ b/environment.yaml @@ -26,4 +26,4 @@ dependencies: - pip - pip: - gamsapi[transfer]==45.0.0 - - pybalmorel==0.3.4 \ No newline at end of file + - pybalmorel==0.3.7 \ No newline at end of file From de496b179cbe9996d137afebc12cdd1307d9b04b Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sun, 22 Sep 2024 14:58:00 +0200 Subject: [PATCH 21/22] A residual placeholder function removed --- RawDataProcessing/Modules/Submodules/utils.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/RawDataProcessing/Modules/Submodules/utils.py b/RawDataProcessing/Modules/Submodules/utils.py index 511ce9b..fdef934 100644 --- a/RawDataProcessing/Modules/Submodules/utils.py +++ b/RawDataProcessing/Modules/Submodules/utils.py @@ -102,22 +102,3 @@ def transform_xrdata(xarray: xr.Dataset, output = output.sel(selection) return output - -def create_geo_sets(geo_sets: Tuple[pd.DataFrame, dict], - prefix: Tuple[str, None] = None): - - IncFile(name='CCCRRRAAA') - if 'C' in geo_sets.keys(): - IncFile(name='CCC') - - if 'R' in geo_sets.keys(): - IncFile(name='CCCRRR') - IncFile(name='RRR') - - if 'A' in geo_sets.keys(): - IncFile(name='RRRAAA') - if prefix != None: - IncFile(name=f'{prefix}_AAA') - else: - IncFile(name='AAA') - \ No newline at end of file From 1c86de4500d3967b22260cfa5f61f3bfd3e6362c Mon Sep 17 00:00:00 2001 From: Mathias157 Date: Sun, 22 Sep 2024 14:58:32 +0200 Subject: [PATCH 22/22] Forgot to remove IncFile import as well --- RawDataProcessing/Modules/Submodules/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/RawDataProcessing/Modules/Submodules/utils.py b/RawDataProcessing/Modules/Submodules/utils.py index fdef934..af9bf3b 100644 --- a/RawDataProcessing/Modules/Submodules/utils.py +++ b/RawDataProcessing/Modules/Submodules/utils.py @@ -13,7 +13,6 @@ from typing import Tuple import pickle import numpy as np -from pybalmorel import IncFile #%% ------------------------------- ### ### 1. Conversion Functions ###