From 731b26cbbc3935e82029ca9329ae2793562a5528 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Tue, 18 Apr 2023 18:59:29 -0400 Subject: [PATCH 01/19] World Battery Start --- libs/resources/resources/__init__.py | 1 + libs/resources/resources/powergrid.py | 25 ++++++++++++++++++++++ libs/resources/resources/worldbattery.json | 1 + libs/resources/setup.py | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 libs/resources/resources/powergrid.py create mode 100644 libs/resources/resources/worldbattery.json diff --git a/libs/resources/resources/__init__.py b/libs/resources/resources/__init__.py index cdc5d38..a6d6556 100644 --- a/libs/resources/resources/__init__.py +++ b/libs/resources/resources/__init__.py @@ -1,3 +1,4 @@ from .fossil import Oil, Coal, NaturalGas from .synthetic import Nuclear from .renewable import Wind, Solar, Water +from .powergrid import PowerGrid diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py new file mode 100644 index 0000000..74af45f --- /dev/null +++ b/libs/resources/resources/powergrid.py @@ -0,0 +1,25 @@ +import json + +class PowerGrid: + + def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): + with open("worldbattery.json", "r") as fh: + + world_battery = json.load(fh) + world_battery["power"] += int(wind) + world_battery["power"] += solar + world_battery["power"] += coal + world_battery["power"] += oil + world_battery["power"] += nuclear + world_battery["power"] += natural_gass + with open("worldbattery", "w") as add_battery: + json.dump(world_battery, add_battery) + + #make an if statement to keep from going to 0 + def use_power(power): + with open("worldbattery", "r") as fh: + world_battery = json.load(fh) + world_battery["power"] -= power + with open("worldbattery", "w") as add_battery: + json.dump(world_battery, add_battery) + diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json new file mode 100644 index 0000000..f7ceb10 --- /dev/null +++ b/libs/resources/resources/worldbattery.json @@ -0,0 +1 @@ +{"power": 0} \ No newline at end of file diff --git a/libs/resources/setup.py b/libs/resources/setup.py index e139429..d946f5a 100644 --- a/libs/resources/setup.py +++ b/libs/resources/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name="resources", version="0.1", - packages=['resources'] + packages=['resources'], include_package_data=True, description='Global resource pool for term-world resources', long_description=open('README.md', 'r').read(), From 858b5599a7c5347851f937ae7370751da04f01fb Mon Sep 17 00:00:00 2001 From: jmsjones12 Date: Wed, 19 Apr 2023 10:03:58 -0400 Subject: [PATCH 02/19] Changes --- libs/resources/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/resources/setup.py b/libs/resources/setup.py index e139429..d946f5a 100644 --- a/libs/resources/setup.py +++ b/libs/resources/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name="resources", version="0.1", - packages=['resources'] + packages=['resources'], include_package_data=True, description='Global resource pool for term-world resources', long_description=open('README.md', 'r').read(), From 821967414f2c63ea9a025106686783b28b3320f0 Mon Sep 17 00:00:00 2001 From: jmsjones12 Date: Wed, 19 Apr 2023 10:42:38 -0400 Subject: [PATCH 03/19] World Battery Work --- libs/resources/resources/powergrid.py | 6 +++--- libs/resources/resources/worldbattery.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index 74af45f..af34e4d 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -12,14 +12,14 @@ def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass world_battery["power"] += oil world_battery["power"] += nuclear world_battery["power"] += natural_gass - with open("worldbattery", "w") as add_battery: + with open("worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) #make an if statement to keep from going to 0 def use_power(power): - with open("worldbattery", "r") as fh: + with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: world_battery = json.load(fh) world_battery["power"] -= power - with open("worldbattery", "w") as add_battery: + with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index f7ceb10..cdb4efd 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"power": 0} \ No newline at end of file +{"power": 5} \ No newline at end of file From 78a2f680e6594e43b5814fbcdae8206282d4f9ea Mon Sep 17 00:00:00 2001 From: Shnacko Date: Wed, 19 Apr 2023 10:45:42 -0400 Subject: [PATCH 04/19] Working add power --- libs/resources/resources/powergrid.py | 9 ++++----- libs/resources/resources/worldbattery.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index 74af45f..280e333 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -3,8 +3,7 @@ class PowerGrid: def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): - with open("worldbattery.json", "r") as fh: - + with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: world_battery = json.load(fh) world_battery["power"] += int(wind) world_battery["power"] += solar @@ -12,14 +11,14 @@ def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass world_battery["power"] += oil world_battery["power"] += nuclear world_battery["power"] += natural_gass - with open("worldbattery", "w") as add_battery: + with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) #make an if statement to keep from going to 0 def use_power(power): - with open("worldbattery", "r") as fh: + with open("worldbattery.json", "r") as fh: world_battery = json.load(fh) world_battery["power"] -= power - with open("worldbattery", "w") as add_battery: + with open("worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index f7ceb10..b70adf5 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"power": 0} \ No newline at end of file +{"power": 0.009600000000000001} \ No newline at end of file From c561c12f07a5078da4d74b2684aa868ac30c48b5 Mon Sep 17 00:00:00 2001 From: Gogurk Date: Thu, 20 Apr 2023 11:41:42 -0400 Subject: [PATCH 05/19] Prototype --- libs/namelog/History/UserHistory.json | 12 +++++++++++ libs/namelog/name.py | 30 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 libs/namelog/History/UserHistory.json create mode 100644 libs/namelog/name.py diff --git a/libs/namelog/History/UserHistory.json b/libs/namelog/History/UserHistory.json new file mode 100644 index 0000000..4e05465 --- /dev/null +++ b/libs/namelog/History/UserHistory.json @@ -0,0 +1,12 @@ +[ + + + + + + + + + + +] \ No newline at end of file diff --git a/libs/namelog/name.py b/libs/namelog/name.py new file mode 100644 index 0000000..205b553 --- /dev/null +++ b/libs/namelog/name.py @@ -0,0 +1,30 @@ +import getpass + + + +def load_file(UserHistory: str = "") -> dict: + """ Loads a file by name """ + with open(UserHistory) as fh: + return json.load(fh) + +def save_file(UserHistory: str = "", User: dict = {}) -> None: + """ Saves data to a file by name """ + with open(UserHistory, "w") as fh: + json.dump(User) + + +def main(): + + User_history = { + "User": user, + + } + + user_names = {} + list = load_file("History/UserHistory.json") + User = user_names + for user in user_names: + dummy = input("Enter text:") + user = getpass.getuser() + user_names.append(user) + print(user) From 88e6c6633bd429cd54310a754300299728c8d121 Mon Sep 17 00:00:00 2001 From: Gogurk Date: Thu, 20 Apr 2023 17:55:57 -0400 Subject: [PATCH 06/19] Functional --- libs/namelog/History/UserHistory.json | 12 ----------- libs/namelog/UserHistory.json | 1 + libs/namelog/name.py | 31 ++++++++++++++++++++++++--- libs/resources/setup.py | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) delete mode 100644 libs/namelog/History/UserHistory.json create mode 100644 libs/namelog/UserHistory.json diff --git a/libs/namelog/History/UserHistory.json b/libs/namelog/History/UserHistory.json deleted file mode 100644 index 4e05465..0000000 --- a/libs/namelog/History/UserHistory.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - - - - - - - - - - -] \ No newline at end of file diff --git a/libs/namelog/UserHistory.json b/libs/namelog/UserHistory.json new file mode 100644 index 0000000..067e650 --- /dev/null +++ b/libs/namelog/UserHistory.json @@ -0,0 +1 @@ +[{"user": "Gogurk", "time": 1682015082.957228}] \ No newline at end of file diff --git a/libs/namelog/name.py b/libs/namelog/name.py index 205b553..5aed97d 100644 --- a/libs/namelog/name.py +++ b/libs/namelog/name.py @@ -1,18 +1,42 @@ +import json import getpass +from datetime import datetime +import time +def now() -> float: + """Returns a float is the time _right now_""" + return datetime.now().timestamp() +# variable user _GETS_ the output of the +# getpass _module_'s getuser _method_. +user = getpass.getuser() +# create users list to add individual users + +users = [] + +users.append({"user": user, "time": now()}) +if users == user: + then users + user + +# save the list as a file + +with open("UserHistory.json", "w") as fh: + json.dump(users, fh) + +""" def load_file(UserHistory: str = "") -> dict: - """ Loads a file by name """ + # Loads a file by name with open(UserHistory) as fh: return json.load(fh) def save_file(UserHistory: str = "", User: dict = {}) -> None: - """ Saves data to a file by name """ + # Saves data to a file by name with open(UserHistory, "w") as fh: json.dump(User) +""" - +""" def main(): User_history = { @@ -28,3 +52,4 @@ def main(): user = getpass.getuser() user_names.append(user) print(user) +""" \ No newline at end of file diff --git a/libs/resources/setup.py b/libs/resources/setup.py index e139429..d946f5a 100644 --- a/libs/resources/setup.py +++ b/libs/resources/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name="resources", version="0.1", - packages=['resources'] + packages=['resources'], include_package_data=True, description='Global resource pool for term-world resources', long_description=open('README.md', 'r').read(), From eaf748006d839391aa5327d276bc6d7eebf17743 Mon Sep 17 00:00:00 2001 From: Gogurk Date: Fri, 21 Apr 2023 15:15:25 -0400 Subject: [PATCH 07/19] Functional --- libs/namelog/UserHistory.json | 2 +- libs/namelog/name.py | 38 ++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libs/namelog/UserHistory.json b/libs/namelog/UserHistory.json index 067e650..e682451 100644 --- a/libs/namelog/UserHistory.json +++ b/libs/namelog/UserHistory.json @@ -1 +1 @@ -[{"user": "Gogurk", "time": 1682015082.957228}] \ No newline at end of file +[{"user": "Gogurk", "time": "Fri Apr 21 14:44:12 2023"}] \ No newline at end of file diff --git a/libs/namelog/name.py b/libs/namelog/name.py index 5aed97d..6161daa 100644 --- a/libs/namelog/name.py +++ b/libs/namelog/name.py @@ -3,26 +3,36 @@ from datetime import datetime import time -def now() -> float: - """Returns a float is the time _right now_""" - return datetime.now().timestamp() +class User_Log -# variable user _GETS_ the output of the -# getpass _module_'s getuser _method_. + def now() -> float: + """Returns a float is the time _right now_""" + return datetime.now().timestamp() -user = getpass.getuser() -# create users list to add individual users + #Converts Epoch time to Date format + local_time = time.ctime(now()) -users = [] -users.append({"user": user, "time": now()}) -if users == user: - then users + user + # variable user _GETS_ the output of the + # getpass _module_'s getuser _method_. + + user = getpass.getuser() + # create users list to add individual users + + users = [] + + + + users.append({"user": user, "time": local_time}) + + + # save the list as a file + + + with open("UserHistory.json", "a") as fh: + json.dump(users, fh) -# save the list as a file -with open("UserHistory.json", "w") as fh: - json.dump(users, fh) """ def load_file(UserHistory: str = "") -> dict: From c31566462c8d9720b8cc0a0d53050cddf565d1f9 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Fri, 21 Apr 2023 15:19:58 -0400 Subject: [PATCH 08/19] Splitting power --- libs/resources/resources/powergrid.py | 14 ++++++++------ libs/resources/resources/worldbattery.json | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index 6094450..41f866d 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -3,14 +3,13 @@ class PowerGrid: def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): + #more generalizable way to do this path + renewable_energy = wind + solar + exhaustable_energy = coal + oil + nuclear + natural_gass with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: world_battery = json.load(fh) - world_battery["power"] += int(wind) - world_battery["power"] += solar - world_battery["power"] += coal - world_battery["power"] += oil - world_battery["power"] += nuclear - world_battery["power"] += natural_gass + world_battery["renewable_energy"] += renewable_energy + world_battery["exhaustable_energy"] += exhaustable_energy with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) @@ -18,7 +17,10 @@ def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass def use_power(power): with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: world_battery = json.load(fh) + if world_battery["power"] >= power: world_battery["power"] -= power + else: + print("There It Not Enough Power In The World To Run This! ") with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index cdb4efd..ce7b8f7 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"power": 5} \ No newline at end of file +{"renewable_energy": 3556.0226289034053, "exhaustable_energy": 0} \ No newline at end of file From b90515f40715e4b8b950dc81267a0fc62ce9b5bc Mon Sep 17 00:00:00 2001 From: Shnacko Date: Fri, 21 Apr 2023 15:43:58 -0400 Subject: [PATCH 09/19] power pulls from renewable first --- libs/resources/resources/powergrid.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index 41f866d..ceaa714 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -17,10 +17,13 @@ def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass def use_power(power): with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: world_battery = json.load(fh) - if world_battery["power"] >= power: - world_battery["power"] -= power - else: + if world_battery["renewable_energy"] >= power: + world_battery["renewable_energy"] -= power + elif world_battery["exhaustable_energy"] >= power: + world_battery["exhaustable_energy"] -= power + elif world_battery["renewable_energy"] < power and world_battery["echaustable_energy"] < power: print("There It Not Enough Power In The World To Run This! ") + with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) From eec3429f09c944827ad2a81c0344d1ada315d132 Mon Sep 17 00:00:00 2001 From: Gogurk <122996429+Gogurk@users.noreply.github.com> Date: Fri, 21 Apr 2023 15:49:30 -0400 Subject: [PATCH 10/19] Update name.py --- libs/namelog/name.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/namelog/name.py b/libs/namelog/name.py index 6161daa..959cfd1 100644 --- a/libs/namelog/name.py +++ b/libs/namelog/name.py @@ -3,7 +3,7 @@ from datetime import datetime import time -class User_Log +class User_Log: def now() -> float: """Returns a float is the time _right now_""" @@ -62,4 +62,4 @@ def main(): user = getpass.getuser() user_names.append(user) print(user) -""" \ No newline at end of file +""" From cf9e928880b0aecd3fa16d2f2aadcf895f5d0a16 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Mon, 24 Apr 2023 16:12:40 -0400 Subject: [PATCH 11/19] Battery updates --- libs/resources/resources/powergrid.py | 12 +++++++++--- libs/resources/resources/worldbattery.json | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index ceaa714..bc92cfc 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -1,7 +1,12 @@ import json +import sys +import os +import resources class PowerGrid: + path = os.path.dirname(resources.__file__) + def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): #more generalizable way to do this path renewable_energy = wind + solar @@ -21,9 +26,10 @@ def use_power(power): world_battery["renewable_energy"] -= power elif world_battery["exhaustable_energy"] >= power: world_battery["exhaustable_energy"] -= power - elif world_battery["renewable_energy"] < power and world_battery["echaustable_energy"] < power: - print("There It Not Enough Power In The World To Run This! ") - + elif world_battery["renewable_energy"] < power and world_battery["exhaustable_energy"] < power: + print("There Is Not Enough Power In The World To Run This! ") + sys.exit() + with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index ce7b8f7..3d1856f 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"renewable_energy": 3556.0226289034053, "exhaustable_energy": 0} \ No newline at end of file +{"renewable_energy": 0, "exhaustable_energy": 0} \ No newline at end of file From 9d361eeeee6e6277c7ee474e9b756097583e28f2 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Mon, 24 Apr 2023 16:13:40 -0400 Subject: [PATCH 12/19] battery updates --- libs/resources/resources/logs/add.log.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 libs/resources/resources/logs/add.log.json diff --git a/libs/resources/resources/logs/add.log.json b/libs/resources/resources/logs/add.log.json new file mode 100644 index 0000000..e69de29 From 2fe1a214532c238077735fba6949f5d94b39c735 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Tue, 25 Apr 2023 11:32:52 -0400 Subject: [PATCH 13/19] os.path.dirname addition --- libs/resources/resources/powergrid.py | 25 ++++++++++++---------- libs/resources/resources/worldbattery.json | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index bc92cfc..65316c8 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -5,31 +5,34 @@ class PowerGrid: - path = os.path.dirname(resources.__file__) - def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): - #more generalizable way to do this path + # sorts power based on its source and adds it to the power grid + path = os.path.dirname(resources.__file__) renewable_energy = wind + solar exhaustable_energy = coal + oil + nuclear + natural_gass - with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: + with open(f"{path}/worldbattery.json", "r") as fh: world_battery = json.load(fh) world_battery["renewable_energy"] += renewable_energy world_battery["exhaustable_energy"] += exhaustable_energy - with open("../../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: + with open(f"{path}/worldbattery.json", "w") as add_battery: json.dump(world_battery, add_battery) - #make an if statement to keep from going to 0 + # Takes a perameter that is the ammount of power it takes to run the object def use_power(power): - with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "r") as fh: + path = os.path.dirname(resources.__file__) + with open(f"{path}/worldbattery.json", "r") as fh: world_battery = json.load(fh) + if world_battery["renewable_energy"] >= power: world_battery["renewable_energy"] -= power + print("You Can Feel Good Knowing This Was Powered By Renewable Energy! ") elif world_battery["exhaustable_energy"] >= power: world_battery["exhaustable_energy"] -= power + print("Hope you are happy. You powered it, but now the earth is a little more polluted.") + print("🏭") elif world_battery["renewable_energy"] < power and world_battery["exhaustable_energy"] < power: - print("There Is Not Enough Power In The World To Run This! ") + print("There Is Not Enough Power In The World. Generate Some More And Try Again. ") sys.exit() - - with open("../term-util-power-planters/libs/resources/resources/worldbattery.json", "w") as add_battery: - json.dump(world_battery, add_battery) + with open(f"{path}/worldbattery.json", "w") as add_battery: + json.dump(world_battery, add_battery) \ No newline at end of file diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index 3d1856f..81b320b 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"renewable_energy": 0, "exhaustable_energy": 0} \ No newline at end of file +{"renewable_energy": 792.46115237941, "exhaustable_energy": 0} \ No newline at end of file From 708e02f226dea3cc04c845c0f51194d0ea0b575b Mon Sep 17 00:00:00 2001 From: Shnacko Date: Thu, 27 Apr 2023 16:09:27 -0400 Subject: [PATCH 14/19] Just testing some things --- libs/namelog/UserHistory.json | 2 +- libs/resources/resources/__init__.py | 1 + .../resources/{logs/add.log.json => log.json} | 0 libs/resources/resources/namelog.py | 34 +++++++++++++++++++ libs/resources/resources/worldbattery.json | 2 +- 5 files changed, 37 insertions(+), 2 deletions(-) rename libs/resources/resources/{logs/add.log.json => log.json} (100%) create mode 100644 libs/resources/resources/namelog.py diff --git a/libs/namelog/UserHistory.json b/libs/namelog/UserHistory.json index e682451..30775c9 100644 --- a/libs/namelog/UserHistory.json +++ b/libs/namelog/UserHistory.json @@ -1 +1 @@ -[{"user": "Gogurk", "time": "Fri Apr 21 14:44:12 2023"}] \ No newline at end of file +{"user": "Gogurk", "time": "Fri Apr 21 14:44:12 2023", "nuclear": 10, "natural_gas": 0, "oil": 10, "coal": 15, "solar": 0, "wind": 0} \ No newline at end of file diff --git a/libs/resources/resources/__init__.py b/libs/resources/resources/__init__.py index a6d6556..36c4497 100644 --- a/libs/resources/resources/__init__.py +++ b/libs/resources/resources/__init__.py @@ -2,3 +2,4 @@ from .synthetic import Nuclear from .renewable import Wind, Solar, Water from .powergrid import PowerGrid +from .namelog import UserLog \ No newline at end of file diff --git a/libs/resources/resources/logs/add.log.json b/libs/resources/resources/log.json similarity index 100% rename from libs/resources/resources/logs/add.log.json rename to libs/resources/resources/log.json diff --git a/libs/resources/resources/namelog.py b/libs/resources/resources/namelog.py new file mode 100644 index 0000000..6cdcba1 --- /dev/null +++ b/libs/resources/resources/namelog.py @@ -0,0 +1,34 @@ +import json +import os +import getpass +from datetime import datetime +import time + +class UserLog: + + # Get the Power added + def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = 0) -> list: + with open("../../term-util-power-planters/libs/resources/resources/log.json", "r") as fh: + log = json.load(fh) + + name = getpass.getuser() + now = time.ctime(datetime.now().timestamp()) + + entry = { + "user": name, + "time": now, + "wind": wind, + "solar": solar, + "coal": coal, + "oil": oil, + "nuclear": nuclear, + "natural_gas": natural_gas + } + + log.append(entry) + + with open("../../term-util-power-planters/libs/resources/resources/log.json", "w") as fh: + json.dump(entry, fh) + + #energy.append({"user": name, "time": now, "wind": wind, "solar": solar, "coal": coal, "oil": oil, "nuclear": nuclear, "natural_gas": natural_gas}) + #path = os.path.dirname(resources.__file__) \ No newline at end of file diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index 81b320b..a4871d2 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"renewable_energy": 792.46115237941, "exhaustable_energy": 0} \ No newline at end of file +{"renewable_energy": 26414.78967642266, "exhaustable_energy": 0} \ No newline at end of file From c52f1cdf0bd1ce8bcc3e1879decdb2282c686c74 Mon Sep 17 00:00:00 2001 From: Shnacko Date: Fri, 28 Apr 2023 10:38:51 -0400 Subject: [PATCH 15/19] prototype namelog --- libs/resources/resources/log.json | 1 + libs/resources/resources/namelog.py | 9 +++++++-- libs/resources/resources/worldbattery.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/resources/resources/log.json b/libs/resources/resources/log.json index e69de29..c367f50 100644 --- a/libs/resources/resources/log.json +++ b/libs/resources/resources/log.json @@ -0,0 +1 @@ +[{"user": "Shnacko", "time": "Fri Apr 28 10:36:27 2023", "wind": 753.8693861972002, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}, {"user": "Shnacko", "time": "Fri Apr 28 10:36:38 2023", "wind": 753.8693861972002, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}] \ No newline at end of file diff --git a/libs/resources/resources/namelog.py b/libs/resources/resources/namelog.py index 6cdcba1..bad8f2d 100644 --- a/libs/resources/resources/namelog.py +++ b/libs/resources/resources/namelog.py @@ -25,10 +25,15 @@ def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = "natural_gas": natural_gas } - log.append(entry) + #length = len(log) + #entry_num = length +1 + + #log[f"{entry_num}"] = entry + + log.append(entry) with open("../../term-util-power-planters/libs/resources/resources/log.json", "w") as fh: - json.dump(entry, fh) + json.dump(log, fh) #energy.append({"user": name, "time": now, "wind": wind, "solar": solar, "coal": coal, "oil": oil, "nuclear": nuclear, "natural_gas": natural_gas}) #path = os.path.dirname(resources.__file__) \ No newline at end of file diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index a4871d2..8a65166 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"renewable_energy": 26414.78967642266, "exhaustable_energy": 0} \ No newline at end of file +{"renewable_energy": 36215.091696986245, "exhaustable_energy": 0} \ No newline at end of file From 8363f233cce12c19128b6dacea823f4f0f942fce Mon Sep 17 00:00:00 2001 From: Gogurk Date: Fri, 28 Apr 2023 14:09:03 -0400 Subject: [PATCH 16/19] Finished Copy --- libs/namelog/UserHistory.json | 1 - libs/namelog/name.py | 65 ------------- .../resources/resources/logs/UserHistory.json | 1 + libs/resources/resources/name.py | 94 +++++++++++++++++++ 4 files changed, 95 insertions(+), 66 deletions(-) delete mode 100644 libs/namelog/UserHistory.json delete mode 100644 libs/namelog/name.py create mode 100644 libs/resources/resources/logs/UserHistory.json create mode 100644 libs/resources/resources/name.py diff --git a/libs/namelog/UserHistory.json b/libs/namelog/UserHistory.json deleted file mode 100644 index e682451..0000000 --- a/libs/namelog/UserHistory.json +++ /dev/null @@ -1 +0,0 @@ -[{"user": "Gogurk", "time": "Fri Apr 21 14:44:12 2023"}] \ No newline at end of file diff --git a/libs/namelog/name.py b/libs/namelog/name.py deleted file mode 100644 index 6161daa..0000000 --- a/libs/namelog/name.py +++ /dev/null @@ -1,65 +0,0 @@ -import json -import getpass -from datetime import datetime -import time - -class User_Log - - def now() -> float: - """Returns a float is the time _right now_""" - return datetime.now().timestamp() - - #Converts Epoch time to Date format - local_time = time.ctime(now()) - - - # variable user _GETS_ the output of the - # getpass _module_'s getuser _method_. - - user = getpass.getuser() - # create users list to add individual users - - users = [] - - - - users.append({"user": user, "time": local_time}) - - - # save the list as a file - - - with open("UserHistory.json", "a") as fh: - json.dump(users, fh) - - - -""" -def load_file(UserHistory: str = "") -> dict: - # Loads a file by name - with open(UserHistory) as fh: - return json.load(fh) - -def save_file(UserHistory: str = "", User: dict = {}) -> None: - # Saves data to a file by name - with open(UserHistory, "w") as fh: - json.dump(User) -""" - -""" -def main(): - - User_history = { - "User": user, - - } - - user_names = {} - list = load_file("History/UserHistory.json") - User = user_names - for user in user_names: - dummy = input("Enter text:") - user = getpass.getuser() - user_names.append(user) - print(user) -""" \ No newline at end of file diff --git a/libs/resources/resources/logs/UserHistory.json b/libs/resources/resources/logs/UserHistory.json new file mode 100644 index 0000000..59558d1 --- /dev/null +++ b/libs/resources/resources/logs/UserHistory.json @@ -0,0 +1 @@ +[{"user": "Gogurk", "time": "Wed Apr 26 10:25:34 2023"}][{"user": "Gogurk", "time": "Wed Apr 26 10:39:45 2023"}][{"user": "Gogurk", "time": "Wed Apr 26 10:42:05 2023"}][{"user": "Gogurk", "time": "Fri Apr 28 10:36:17 2023"}] \ No newline at end of file diff --git a/libs/resources/resources/name.py b/libs/resources/resources/name.py new file mode 100644 index 0000000..36d81af --- /dev/null +++ b/libs/resources/resources/name.py @@ -0,0 +1,94 @@ +import os +import json +import getpass +import main +from datetime import datetime +import time + +class User_Log: + + def now() -> float: + """Returns a float is the time _right now_""" + return datetime.now().timestamp() + + + #Converts Epoch time to Date format + local_time = time.ctime(now()) + + + # variable user _GETS_ the output of the + # getpass _module_'s getuser _method_. + + user = getpass.getuser() + # create users list to add individual users + + users = [] + + + + renewable = solar_energy + wind_energy + nonrenewable = coal_energy + oil_energy + users.append({"user": user, "time": local_time, "renewable": renewable , "nonrenewable": nonrenewable}) + + + # save the list as a file + with open("logs/UserHistory.json", "a") as fh: + json.dump(users, fh) + + #myfolder = "/libs/resources/resources/logs/" + #fileToWrite = open(f"{myfolder}/{UserHistory.json}", "a") + + +# with open("UserHistory.json", "a") as fh: +# json.dump(users, fh) +# #working + + +# with open("/logs/UserHistory.json", "a") as fh: +# json.dump(users, fh) + + +# path = os.path.dirname(resources.__file__) +# with open(f"{path}/resources/resources/logs/UserHistory.json", "a") as fh: +# json.dump(users, fh) + +# path = os.path.dirname(resources.__file__) +# with open(f"{path}/UserHistory.json", "a") as fh: +# json.dump(users, fh) + +# if __name__ == "__main__": +# main() + +# def power(wind, solar, coal): +# renewable = wind + soalr + +# return renewable, + + + + +# def load_file(UserHistory: str = "") -> dict: +# # Loads a file by name +# with open(UserHistory) as fh: +# return json.load(fh) + +# def save_file(UserHistory: str = "", User: dict = {}) -> None: +# # Saves data to a file by name +# with open(UserHistory, "w") as fh: +# json.dump(User) + +# def main(): + +# User_history = { +# "User": user, + +# } + +# user_names = {} +# list = load_file("History/UserHistory.json") +# User = user_names +# for user in user_names: +# dummy = input("Enter text:") +# user = getpass.getuser() +# user_names.append(user) +# print(user) From 9ee5deeec900a7118038c14c3dda94879b515237 Mon Sep 17 00:00:00 2001 From: Gogurk Date: Fri, 28 Apr 2023 14:37:51 -0400 Subject: [PATCH 17/19] Finished --- .../resources/resources/logs/UserHistory.json | 1 + libs/resources/resources/name.py | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 libs/resources/resources/logs/UserHistory.json create mode 100644 libs/resources/resources/name.py diff --git a/libs/resources/resources/logs/UserHistory.json b/libs/resources/resources/logs/UserHistory.json new file mode 100644 index 0000000..7c44ddf --- /dev/null +++ b/libs/resources/resources/logs/UserHistory.json @@ -0,0 +1 @@ +[{"user": "Gogurk", "time": "Mon Apr 24 10:12:18 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:12:52 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:14:17 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:18:10 2023"}][{"user": "Gogurk", "time": "Fri Apr 28 10:51:12 2023"}][{"user": "Gogurk", "time": "Fri Apr 28 14:36:48 2023"}] \ No newline at end of file diff --git a/libs/resources/resources/name.py b/libs/resources/resources/name.py new file mode 100644 index 0000000..adb33bf --- /dev/null +++ b/libs/resources/resources/name.py @@ -0,0 +1,94 @@ +import os +import main +import json +import getpass +from datetime import datetime +import time + +class User_Log: + + def now() -> float: + """Returns a float is the time _right now_""" + return datetime.now().timestamp() + + + #Converts Epoch time to Date format + local_time = time.ctime(now()) + + + # variable user _GETS_ the output of the + # getpass _module_'s getuser _method_. + + user = getpass.getuser() + # create users list to add individual users + + users = [] + + + renewable = solar_energy + wind_energy + nonrenewable = coal_energy + oil_energy + users.append({"user": user, "time": local_time, "renewable": renewable , "nonrenewable": nonrenewable}) + + + + # save the list as a file + with open("logs/UserHistory.json", "a") as fh: + json.dump(users, fh) + + #myfolder = "/libs/resources/resources/logs/" + #fileToWrite = open(f"{myfolder}/{UserHistory.json}", "a") + + +# with open("UserHistory.json", "a") as fh: +# json.dump(users, fh) +# #working + + +# with open("/logs/UserHistory.json", "a") as fh: +# json.dump(users, fh) + + +# path = os.path.dirname(resources.__file__) +# with open(f"{path}/resources/resources/logs/UserHistory.json", "a") as fh: +# json.dump(users, fh) + +# path = os.path.dirname(resources.__file__) +# with open(f"{path}/UserHistory.json", "a") as fh: +# json.dump(users, fh) + +# if __name__ == "__main__": +# main() + +# def power(wind, solar, coal): +# renewable = wind + soalr + +# return renewable, + + + + +# def load_file(UserHistory: str = "") -> dict: +# # Loads a file by name +# with open(UserHistory) as fh: +# return json.load(fh) + +# def save_file(UserHistory: str = "", User: dict = {}) -> None: +# # Saves data to a file by name +# with open(UserHistory, "w") as fh: +# json.dump(User) + +# def main(): + +# User_history = { +# "User": user, + +# } + +# user_names = {} +# list = load_file("History/UserHistory.json") +# User = user_names +# for user in user_names: +# dummy = input("Enter text:") +# user = getpass.getuser() +# user_names.append(user) +# print(user) From d81511538dd747732c15efa30f52fc3919db9dc6 Mon Sep 17 00:00:00 2001 From: Gogurk Date: Fri, 28 Apr 2023 16:25:36 -0400 Subject: [PATCH 18/19] Test 2 From 57a6e8d01fbb4e0e35fd3ad9ce0ec2eb318eabcf Mon Sep 17 00:00:00 2001 From: Shnacko Date: Sun, 7 May 2023 15:01:16 -0400 Subject: [PATCH 19/19] FINAL CODE --- libs/resources/resources/log.json | 2 +- .../resources/resources/logs/UserHistory.json | 1 - libs/resources/resources/name.py | 94 ------------------- libs/resources/resources/namelog.py | 20 ++-- libs/resources/resources/powergrid.py | 8 +- libs/resources/resources/worldbattery.json | 2 +- 6 files changed, 12 insertions(+), 115 deletions(-) delete mode 100644 libs/resources/resources/logs/UserHistory.json delete mode 100644 libs/resources/resources/name.py diff --git a/libs/resources/resources/log.json b/libs/resources/resources/log.json index c367f50..1ffc5f0 100644 --- a/libs/resources/resources/log.json +++ b/libs/resources/resources/log.json @@ -1 +1 @@ -[{"user": "Shnacko", "time": "Fri Apr 28 10:36:27 2023", "wind": 753.8693861972002, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}, {"user": "Shnacko", "time": "Fri Apr 28 10:36:38 2023", "wind": 753.8693861972002, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}] \ No newline at end of file +[{"user": "Shnacko", "time": 1682952779.590532, "wind": 4533.017306686408, "solar": 0, "coal": 0, "oil": 0, "nuclear": 0, "natural_gas": 0}] \ No newline at end of file diff --git a/libs/resources/resources/logs/UserHistory.json b/libs/resources/resources/logs/UserHistory.json deleted file mode 100644 index 7c44ddf..0000000 --- a/libs/resources/resources/logs/UserHistory.json +++ /dev/null @@ -1 +0,0 @@ -[{"user": "Gogurk", "time": "Mon Apr 24 10:12:18 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:12:52 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:14:17 2023"}][{"user": "Gogurk", "time": "Mon Apr 24 10:18:10 2023"}][{"user": "Gogurk", "time": "Fri Apr 28 10:51:12 2023"}][{"user": "Gogurk", "time": "Fri Apr 28 14:36:48 2023"}] \ No newline at end of file diff --git a/libs/resources/resources/name.py b/libs/resources/resources/name.py deleted file mode 100644 index 8c1c31b..0000000 --- a/libs/resources/resources/name.py +++ /dev/null @@ -1,94 +0,0 @@ -import os -import main -import json -import getpass -from datetime import datetime -import time - -class User_Log: - - def now() -> float: - """Returns a float is the time _right now_""" - return datetime.now().timestamp() - - - #Converts Epoch time to Date format - local_time = time.ctime(now()) - - - # variable user _GETS_ the output of the - # getpass _module_'s getuser _method_. - - user = getpass.getuser() - # create users list to add individual users - - users = [] - - - - renewable = solar_energy + wind_energy - nonrenewable = coal_energy + oil_energy - users.append({"user": user, "time": local_time, "renewable": renewable , "nonrenewable": nonrenewable}) - - - # save the list as a file - with open("logs/UserHistory.json", "a") as fh: - json.dump(users, fh) - - #myfolder = "/libs/resources/resources/logs/" - #fileToWrite = open(f"{myfolder}/{UserHistory.json}", "a") - - -# with open("UserHistory.json", "a") as fh: -# json.dump(users, fh) -# #working - - -# with open("/logs/UserHistory.json", "a") as fh: -# json.dump(users, fh) - - -# path = os.path.dirname(resources.__file__) -# with open(f"{path}/resources/resources/logs/UserHistory.json", "a") as fh: -# json.dump(users, fh) - -# path = os.path.dirname(resources.__file__) -# with open(f"{path}/UserHistory.json", "a") as fh: -# json.dump(users, fh) - -# if __name__ == "__main__": -# main() - -# def power(wind, solar, coal): -# renewable = wind + soalr - -# return renewable, - - - - -# def load_file(UserHistory: str = "") -> dict: -# # Loads a file by name -# with open(UserHistory) as fh: -# return json.load(fh) - -# def save_file(UserHistory: str = "", User: dict = {}) -> None: -# # Saves data to a file by name -# with open(UserHistory, "w") as fh: -# json.dump(User) - -# def main(): - -# User_history = { -# "User": user, - -# } - -# user_names = {} -# list = load_file("History/UserHistory.json") -# User = user_names -# for user in user_names: -# dummy = input("Enter text:") -# user = getpass.getuser() -# user_names.append(user) -# print(user) diff --git a/libs/resources/resources/namelog.py b/libs/resources/resources/namelog.py index bad8f2d..d283146 100644 --- a/libs/resources/resources/namelog.py +++ b/libs/resources/resources/namelog.py @@ -6,13 +6,13 @@ class UserLog: - # Get the Power added - def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = 0) -> list: - with open("../../term-util-power-planters/libs/resources/resources/log.json", "r") as fh: + def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = 0): + path = os.path.dirname(__file__) + with open(f"{path}/log.json", "r") as fh: log = json.load(fh) name = getpass.getuser() - now = time.ctime(datetime.now().timestamp()) + now = datetime.now().timestamp() entry = { "user": name, @@ -25,15 +25,7 @@ def log_user(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gas = "natural_gas": natural_gas } - #length = len(log) - #entry_num = length +1 - - #log[f"{entry_num}"] = entry - log.append(entry) - with open("../../term-util-power-planters/libs/resources/resources/log.json", "w") as fh: - json.dump(log, fh) - - #energy.append({"user": name, "time": now, "wind": wind, "solar": solar, "coal": coal, "oil": oil, "nuclear": nuclear, "natural_gas": natural_gas}) - #path = os.path.dirname(resources.__file__) \ No newline at end of file + with open(f"{path}/log.json", "w") as fh: + json.dump(log, fh) \ No newline at end of file diff --git a/libs/resources/resources/powergrid.py b/libs/resources/resources/powergrid.py index 65316c8..457c9ea 100644 --- a/libs/resources/resources/powergrid.py +++ b/libs/resources/resources/powergrid.py @@ -1,13 +1,13 @@ import json import sys import os -import resources class PowerGrid: - + + #Turn this perameter into a dictionary def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass = 0): # sorts power based on its source and adds it to the power grid - path = os.path.dirname(resources.__file__) + path = os.path.dirname(__file__) renewable_energy = wind + solar exhaustable_energy = coal + oil + nuclear + natural_gass with open(f"{path}/worldbattery.json", "r") as fh: @@ -19,7 +19,7 @@ def add_power(wind = 0, solar = 0, coal = 0, oil = 0, nuclear = 0, natural_gass # Takes a perameter that is the ammount of power it takes to run the object def use_power(power): - path = os.path.dirname(resources.__file__) + path = os.path.dirname(__file__) with open(f"{path}/worldbattery.json", "r") as fh: world_battery = json.load(fh) diff --git a/libs/resources/resources/worldbattery.json b/libs/resources/resources/worldbattery.json index 8a65166..d4bee0a 100644 --- a/libs/resources/resources/worldbattery.json +++ b/libs/resources/resources/worldbattery.json @@ -1 +1 @@ -{"renewable_energy": 36215.091696986245, "exhaustable_energy": 0} \ No newline at end of file +{"renewable_energy": 54332.16092373188, "exhaustable_energy": 52808} \ No newline at end of file