Create a material database
This commit is contained in:
parent
8e09e9da20
commit
4e2a1691a3
2 changed files with 61 additions and 8 deletions
|
@ -1,10 +1,19 @@
|
|||
import dataclasses
|
||||
import enum
|
||||
import fractions
|
||||
import typing
|
||||
|
||||
from returns.maybe import Maybe, Some, Nothing
|
||||
|
||||
materials = {
|
||||
"raw": {
|
||||
|
||||
class MaterialType(enum.Enum):
|
||||
raw = "Raw"
|
||||
manufactured = "Manufactured"
|
||||
encoded = "Encoded"
|
||||
|
||||
|
||||
categorized = {
|
||||
MaterialType.raw: {
|
||||
"Raw Material Category 1": ["Carbon", "Vanadium", "Niobium", "Yttrium"],
|
||||
"Raw Material Category 2": [
|
||||
"Phosphorus",
|
||||
|
@ -18,7 +27,7 @@ materials = {
|
|||
"Raw Material Category 6": ["Rhenium", "Arsenic", "Mercury", "Polonium"],
|
||||
"Raw Material Category 7": ["Lead", "Zirconium", "Boron", "Antimony"],
|
||||
},
|
||||
"manufactured": {
|
||||
MaterialType.manufactured: {
|
||||
"Chemical": [
|
||||
"Chemical Storage Units",
|
||||
"Chemical Processors",
|
||||
|
@ -90,7 +99,7 @@ materials = {
|
|||
"Proto Radiolic Alloys",
|
||||
],
|
||||
},
|
||||
"encoded": {
|
||||
MaterialType.encoded: {
|
||||
"Emission Data": [
|
||||
"Exceptional Scrambled Emission Data",
|
||||
"Irregular Emission Data",
|
||||
|
@ -140,12 +149,15 @@ materials = {
|
|||
@dataclasses.dataclass
|
||||
class Material:
|
||||
name: str
|
||||
type_: MaterialType
|
||||
category: str
|
||||
grade: int
|
||||
|
||||
MAX_CAPACITY: int = 300
|
||||
|
||||
def trade_ratio(self, other: "Material") -> Maybe[fractions.Fraction]:
|
||||
if self.type_ != other.type_:
|
||||
return Nothing
|
||||
grade_base = 3 if self.grade <= other.grade else 6
|
||||
grade_ratio = fractions.Fraction(
|
||||
grade_base ** self.grade, grade_base ** other.grade
|
||||
|
@ -160,3 +172,11 @@ class Material:
|
|||
return Nothing
|
||||
else:
|
||||
return Some(ratio)
|
||||
|
||||
|
||||
materials: typing.Dict[str, Material] = {
|
||||
name: Material(name, type_, category, grade)
|
||||
for type_, categories in categorized.items()
|
||||
for category, names in categories.items()
|
||||
for grade, name in enumerate(names)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import fractions
|
||||
import unittest
|
||||
|
||||
from returns.curry import partial
|
||||
from returns.maybe import Maybe
|
||||
|
||||
from elite_engineering import trade
|
||||
|
@ -19,10 +20,16 @@ class TradeCalculationTests(unittest.TestCase):
|
|||
["-", "216 → 1", "36 → 1", "6 → 1", "1 → 1"],
|
||||
]
|
||||
|
||||
material = partial(
|
||||
trade.Material,
|
||||
"name",
|
||||
trade.MaterialType.raw,
|
||||
"category",
|
||||
)
|
||||
actual = [
|
||||
[
|
||||
trade.Material("name", "category", grade_in)
|
||||
.trade_ratio(trade.Material("name", "category", grade_out))
|
||||
material(grade_in)
|
||||
.trade_ratio(material(grade_out))
|
||||
.map(self.format_ratio)
|
||||
.value_or("-")
|
||||
for grade_out in [1, 2, 3, 4, 5]
|
||||
|
@ -41,10 +48,36 @@ class TradeCalculationTests(unittest.TestCase):
|
|||
["-", "-", "216 → 1", "36 → 1", "6 → 1"],
|
||||
]
|
||||
|
||||
type_ = trade.MaterialType.raw
|
||||
material = partial(trade.Material, "name", trade.MaterialType.raw)
|
||||
actual = [
|
||||
[
|
||||
trade.Material("name", "category", grade_in)
|
||||
.trade_ratio(trade.Material("name", "other", grade_out))
|
||||
material("category", grade_in)
|
||||
.trade_ratio(material("other", grade_out))
|
||||
.map(self.format_ratio)
|
||||
.value_or("-")
|
||||
for grade_out in [1, 2, 3, 4, 5]
|
||||
]
|
||||
for grade_in in [1, 2, 3, 4, 5]
|
||||
]
|
||||
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_different_type_exchange(self) -> None:
|
||||
expected = [
|
||||
["-", "-", "-", "-", "-"],
|
||||
["-", "-", "-", "-", "-"],
|
||||
["-", "-", "-", "-", "-"],
|
||||
["-", "-", "-", "-", "-"],
|
||||
["-", "-", "-", "-", "-"],
|
||||
]
|
||||
|
||||
type_ = trade.MaterialType.raw
|
||||
material = partial(trade.Material, "name")
|
||||
actual = [
|
||||
[
|
||||
material(trade.MaterialType.raw, "category", grade_in)
|
||||
.trade_ratio(material(trade.MaterialType.encoded, "other", grade_out))
|
||||
.map(self.format_ratio)
|
||||
.value_or("-")
|
||||
for grade_out in [1, 2, 3, 4, 5]
|
||||
|
|
Loading…
Add table
Reference in a new issue