mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-15 04:28:18 -04:00
adding user for dov
This commit is contained in:
35
capasitor.py
Normal file
35
capasitor.py
Normal file
@@ -0,0 +1,35 @@
|
||||
def calculate_capacitor_capacity(voltage, farads):
|
||||
joules = (farads * voltage**2) // 2
|
||||
return joules // 3600
|
||||
|
||||
|
||||
def calculate_pack_capacity(cells, cell_voltage, farads):
|
||||
return calculate_capacitor_capacity(cells * cell_voltage, farads / cells)
|
||||
|
||||
|
||||
def calculate_pack_capacity2(cells, cell_voltage, farads, cell_cost):
|
||||
capacitor_capacity = calculate_capacitor_capacity(
|
||||
cells * cell_voltage, farads / cells
|
||||
)
|
||||
return capacitor_capacity, cell_cost * cells
|
||||
|
||||
|
||||
def main():
|
||||
watt_hours = calculate_pack_capacity(cells=10, cell_voltage=2.7, farads=500)
|
||||
print(f"{watt_hours=}")
|
||||
print(f"{watt_hours*16=}")
|
||||
watt_hours = calculate_pack_capacity(cells=1, cell_voltage=2.7, farads=5000)
|
||||
print(f"{watt_hours=}")
|
||||
|
||||
watt_hours, cost = calculate_pack_capacity2(
|
||||
cells=10,
|
||||
cell_voltage=2.7,
|
||||
farads=3000,
|
||||
cell_cost=11.60,
|
||||
)
|
||||
print(f"{watt_hours=}")
|
||||
print(f"{cost=}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
dc_charger.py
Normal file
19
dc_charger.py
Normal file
@@ -0,0 +1,19 @@
|
||||
def dc_charger_on(
|
||||
battery_max_kwh: float,
|
||||
battery_current_kwh: float,
|
||||
solar_max_kwh: float,
|
||||
daily_power_kwh: float,
|
||||
night: bool,
|
||||
) -> bool:
|
||||
battery_free_kwh = battery_max_kwh - battery_current_kwh
|
||||
|
||||
if daily_power_kwh <= battery_current_kwh or night:
|
||||
return True
|
||||
|
||||
if battery_current_kwh >= battery_max_kwh:
|
||||
return False
|
||||
|
||||
if solar_max_kwh >= battery_free_kwh:
|
||||
return False
|
||||
|
||||
return True
|
||||
1
file_sizes.txt.new
Normal file
1
file_sizes.txt.new
Normal file
File diff suppressed because one or more lines are too long
258
temp_flake.lock
Normal file
258
temp_flake.lock
Normal file
@@ -0,0 +1,258 @@
|
||||
{
|
||||
"nodes": {
|
||||
"firefox-addons": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"dir": "pkgs/firefox-addons",
|
||||
"lastModified": 1757649814,
|
||||
"narHash": "sha256-VjtA+fqkraKHbGzjKJBPfDj+SXysXiR4SrghTr10HoY=",
|
||||
"owner": "rycee",
|
||||
"repo": "nur-expressions",
|
||||
"rev": "789920825fc982a93a2bf91a714367fa8f7ea0a6",
|
||||
"type": "gitlab"
|
||||
},
|
||||
"original": {
|
||||
"dir": "pkgs/firefox-addons",
|
||||
"owner": "rycee",
|
||||
"repo": "nur-expressions",
|
||||
"type": "gitlab"
|
||||
}
|
||||
},
|
||||
"home-manager": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1757698511,
|
||||
"narHash": "sha256-UqHHGydF/q3jfYXCpvYLA0TWtvByOp1NwOKCUjhYmPs=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "a3fcc92180c7462082cd849498369591dfb20855",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixos-hardware": {
|
||||
"locked": {
|
||||
"lastModified": 1757103352,
|
||||
"narHash": "sha256-PtT7ix43ss8PONJ1VJw3f6t2yAoGH+q462Sn8lrmWmk=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixos-hardware",
|
||||
"rev": "11b2a10c7be726321bb854403fdeec391e798bf0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "master",
|
||||
"repo": "nixos-hardware",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1757487488,
|
||||
"narHash": "sha256-zwE/e7CuPJUWKdvvTCB7iunV4E/+G0lKfv4kk/5Izdg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ab0f3607a6c7486ea22229b92ed2d355f1482ee0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-master": {
|
||||
"locked": {
|
||||
"lastModified": 1757720853,
|
||||
"narHash": "sha256-VBS5+YKIT8Aj81ZW+8Bg9MuYoI6OqO6HSrwG4dpHpW4=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2ca437b4796d049192eb30576a50fef139038c09",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "master",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1735563628,
|
||||
"narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pyproject-build-systems": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"system_tools",
|
||||
"nixpkgs"
|
||||
],
|
||||
"pyproject-nix": [
|
||||
"system_tools",
|
||||
"pyproject-nix"
|
||||
],
|
||||
"uv2nix": [
|
||||
"system_tools",
|
||||
"uv2nix"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1744599653,
|
||||
"narHash": "sha256-nysSwVVjG4hKoOjhjvE6U5lIKA8sEr1d1QzEfZsannU=",
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "build-system-pkgs",
|
||||
"rev": "7dba6dbc73120e15b558754c26024f6c93015dd7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "build-system-pkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pyproject-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"system_tools",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1746540146,
|
||||
"narHash": "sha256-QxdHGNpbicIrw5t6U3x+ZxeY/7IEJ6lYbvsjXmcxFIM=",
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "pyproject.nix",
|
||||
"rev": "e09c10c24ebb955125fda449939bfba664c467fd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "pyproject.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"firefox-addons": "firefox-addons",
|
||||
"home-manager": "home-manager",
|
||||
"nixos-hardware": "nixos-hardware",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs-master": "nixpkgs-master",
|
||||
"nixpkgs-stable": "nixpkgs-stable",
|
||||
"sops-nix": "sops-nix",
|
||||
"system_tools": "system_tools",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"sops-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1757503115,
|
||||
"narHash": "sha256-S9F6bHUBh+CFEUalv/qxNImRapCxvSnOzWBUZgK1zDU=",
|
||||
"owner": "Mic92",
|
||||
"repo": "sops-nix",
|
||||
"rev": "0bf793823386187dff101ee2a9d4ed26de8bbf8c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "Mic92",
|
||||
"repo": "sops-nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"system_tools": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"pyproject-build-systems": "pyproject-build-systems",
|
||||
"pyproject-nix": "pyproject-nix",
|
||||
"uv2nix": "uv2nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1757910132,
|
||||
"narHash": "sha256-6r45DD/tMN+hYgnMc2/c82Z0bb1A7FnI/nvU8kZf/Us=",
|
||||
"owner": "RichieCahill",
|
||||
"repo": "system_tools",
|
||||
"rev": "d63c486fe3b76c24b2ed2fff33d6f54c847b50e8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "RichieCahill",
|
||||
"repo": "system_tools",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1689347949,
|
||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default-linux",
|
||||
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default-linux",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"uv2nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"system_tools",
|
||||
"nixpkgs"
|
||||
],
|
||||
"pyproject-nix": [
|
||||
"system_tools",
|
||||
"pyproject-nix"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1747441483,
|
||||
"narHash": "sha256-W8BFXk5R0TuJcjIhcGoMpSOaIufGXpizK0pm+uTqynA=",
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "uv2nix",
|
||||
"rev": "582024dc64663e9f88d467c2f7f7b20d278349de",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "pyproject-nix",
|
||||
"repo": "uv2nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
68
thing.py
Normal file
68
thing.py
Normal file
@@ -0,0 +1,68 @@
|
||||
def caculat_batry_specs(cell_amp_hour, cell_voltage, cells_per_pack, packs):
|
||||
pack_voltage = cell_voltage * cells_per_pack
|
||||
|
||||
pack_watt_hours = pack_voltage * cell_amp_hour
|
||||
|
||||
battry_capacity = pack_watt_hours * packs
|
||||
return (
|
||||
battry_capacity,
|
||||
pack_voltage,
|
||||
)
|
||||
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(300, 3.2, 8, 2)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 1700
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(300, 3.2, 8, 4)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 3300
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
|
||||
3300/32
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(600, 12.8, 2, 1)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = (740 * 2)
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(300, 12.8, 2, 2)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 330 * 4
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
print("a")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(280, 3.2, 8, 1)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 130 * 8
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(200, 48, 1, 1)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 2060
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(600, 12, 2, 1)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 740 * 2
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(400, 12, 2, 1)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 590 * 2
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
battry_capacity, pack_voltage = caculat_batry_specs(100, 3.2, 8, 4)
|
||||
print(f"{battry_capacity=} {pack_voltage=}")
|
||||
cost = 880 * 2
|
||||
print({f"{cost=}"})
|
||||
print(f"$/kWh {cost / battry_capacity}")
|
||||
|
||||
172
voltage_drop.py
Normal file
172
voltage_drop.py
Normal file
@@ -0,0 +1,172 @@
|
||||
from enum import Enum
|
||||
import math
|
||||
|
||||
|
||||
class TemperatureUnit(Enum):
|
||||
CELSIUS = "c"
|
||||
FAHRENHEIT = "f"
|
||||
KELVIN = "k"
|
||||
|
||||
|
||||
class Temperature:
|
||||
def __init__(
|
||||
self,
|
||||
temperature: float,
|
||||
unit: TemperatureUnit = TemperatureUnit.CELSIUS,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
temperature (float): Temperature in degrees Celsius
|
||||
unit (TemperatureUnit, optional): Temperature unit. Defaults to TemperatureUnit.CELSIUS.
|
||||
"""
|
||||
unit_modifier = {
|
||||
TemperatureUnit.CELSIUS: 1,
|
||||
TemperatureUnit.FAHRENHEIT: 0.5556,
|
||||
TemperatureUnit.KELVIN: 1.8,
|
||||
}
|
||||
self.temperature = temperature * unit_modifier[unit]
|
||||
|
||||
def __float__(self) -> float:
|
||||
return self.temperature
|
||||
|
||||
|
||||
class LengthUnit(Enum):
|
||||
METERS = "m"
|
||||
FEET = "ft"
|
||||
INCHES = "in"
|
||||
|
||||
|
||||
class Length:
|
||||
def __init__(self, length: float, unit: LengthUnit):
|
||||
self.meters = self._convert_to_meters(length, unit)
|
||||
|
||||
def _convert_to_meters(self, length: float, unit: LengthUnit) -> float:
|
||||
thing = {
|
||||
LengthUnit.METERS: 1,
|
||||
LengthUnit.FEET: 0.3048,
|
||||
LengthUnit.INCHES: 0.0254,
|
||||
}
|
||||
test = thing.get(unit)
|
||||
if test:
|
||||
return length * test
|
||||
raise ValueError(f"Unsupported unit: {unit}")
|
||||
|
||||
def __float__(self):
|
||||
return self.meters
|
||||
|
||||
def feet(self) -> float:
|
||||
return self.meters * 3.2808
|
||||
|
||||
|
||||
class MaterialType(Enum):
|
||||
COPPER = "copper"
|
||||
ALUMINUM = "aluminum"
|
||||
CCA = "cca"
|
||||
SILVER = "silver"
|
||||
GOLD = "gold"
|
||||
|
||||
|
||||
def get_material_resistivity(
|
||||
material: MaterialType,
|
||||
temperature: Temperature = Temperature(20.0),
|
||||
) -> float:
|
||||
material_info = {
|
||||
MaterialType.COPPER: (1.724e-8, 0.00393),
|
||||
MaterialType.ALUMINUM: (2.908e-8, 0.00403),
|
||||
MaterialType.CCA: (2.577e-8, 0.00397),
|
||||
MaterialType.SILVER: (1.632e-8, 0.00380),
|
||||
MaterialType.GOLD: (2.503e-8, 0.00340),
|
||||
}
|
||||
|
||||
base_resistivity, temp_coefficient = material_info[material]
|
||||
return base_resistivity * (1 + temp_coefficient * float(temperature))
|
||||
|
||||
|
||||
def calculate_awg_diameter_mm(gauge: int) -> float:
|
||||
"""
|
||||
Calculate wire diameter in millimeters for a given AWG gauge.
|
||||
Formula: diameter = 0.127 * 92^((36-gauge)/39)
|
||||
Where:
|
||||
- 0.127mm is the diameter of AWG 36
|
||||
- 92 is the ratio of diameters between AWG 0000 and AWG 36
|
||||
- 39 is the number of steps between AWG 0000 and AWG 36
|
||||
"""
|
||||
return round(0.127 * 92 ** ((36 - gauge) / 39), 3)
|
||||
|
||||
|
||||
def calculate_wire_area_m2(gauge: int) -> float:
|
||||
"""Calculate the area of a wire in square meters.
|
||||
|
||||
Args:
|
||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
||||
|
||||
Returns:
|
||||
float: The area of the wire in square meters
|
||||
"""
|
||||
return math.pi * (calculate_awg_diameter_mm(gauge) / 2000) ** 2
|
||||
|
||||
|
||||
def calculate_resistance_per_meter(gauge: int) -> float:
|
||||
"""Calculate the resistance per meter of a wire.
|
||||
|
||||
Args:
|
||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
||||
|
||||
Returns:
|
||||
float: The resistance per meter of the wire
|
||||
"""
|
||||
return get_material_resistivity(MaterialType.COPPER) / calculate_wire_area_m2(gauge)
|
||||
|
||||
|
||||
def voltage_drop(
|
||||
gauge: int,
|
||||
material: MaterialType,
|
||||
length: Length,
|
||||
current_a: float,
|
||||
) -> float:
|
||||
resistivity = get_material_resistivity(material)
|
||||
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
||||
total_resistance = resistance_per_meter * float(length) * 2 # round-trip
|
||||
return total_resistance * current_a
|
||||
|
||||
|
||||
print(
|
||||
voltage_drop(
|
||||
gauge=10,
|
||||
material=MaterialType.CCA,
|
||||
length=Length(length=20, unit=LengthUnit.FEET),
|
||||
current_a=20,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def max_wire_length(
|
||||
gauge: int,
|
||||
material: MaterialType,
|
||||
current_amps: float,
|
||||
voltage_drop: float = 0.3,
|
||||
temperature: Temperature = Temperature(100.0, unit=TemperatureUnit.FAHRENHEIT),
|
||||
) -> Length:
|
||||
"""Calculate the maximum allowable wire length based on voltage drop criteria.
|
||||
|
||||
Args:
|
||||
gauge (int): The AWG (American Wire Gauge) number of the wire
|
||||
material (MaterialType): The type of conductor material (e.g., copper, aluminum)
|
||||
current_amps (float): The current flowing through the wire in amperes
|
||||
voltage_drop (float, optional): Maximum allowable voltage drop as a decimal (default 0.1 or 10%)
|
||||
|
||||
Returns:
|
||||
float: Maximum wire length in meters that maintains the specified voltage drop
|
||||
"""
|
||||
resistivity = get_material_resistivity(material, temperature)
|
||||
resistance_per_meter = resistivity / calculate_wire_area_m2(gauge)
|
||||
# V = IR, solve for length where V is the allowed voltage drop
|
||||
return Length(
|
||||
voltage_drop / (current_amps * resistance_per_meter),
|
||||
LengthUnit.METERS,
|
||||
)
|
||||
|
||||
|
||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=20).feet())
|
||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=10).feet())
|
||||
print(max_wire_length(gauge=10, material=MaterialType.CCA, current_amps=5).feet())
|
||||
Reference in New Issue
Block a user