-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
87 lines (75 loc) · 2.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import unittest
import csv
import logging
import configparser
from abc import ABC, abstractmethod
# Set up logging
logging.basicConfig(level=logging.DEBUG)
# Abstract strategies
class HairColorFormulaStrategy(ABC):
@abstractmethod
def choose_developer(self, natural_level, desired_level, hair_condition):
pass
@abstractmethod
def get_grey_coverage_formula(self, grey_percentage):
pass
@abstractmethod
def choose_push_tone(self, desired_tone):
pass
# Concrete strategies
class DefaultHairColorFormulaStrategy(HairColorFormulaStrategy):
def choose_developer(self, natural_level, desired_level, hair_condition):
if natural_level <= desired_level:
return "10 vol"
elif natural_level + 1 <= desired_level:
return "20 vol"
elif natural_level + 2 <= desired_level:
return "30 vol"
else:
return "40 vol"
def get_grey_coverage_formula(self, grey_percentage):
if grey_percentage <= 25:
return "2"
elif grey_percentage <= 50:
return "3"
else:
return "4"
def choose_push_tone(self, desired_tone):
if desired_tone == "neutral":
return ""
elif desired_tone == "warm":
return "W"
else:
return "C"
class HairColorFormula:
def __init__(self, natural_level, desired_level, desired_tone, grey_percentage, coverage_type, hair_condition, desired_result, desired_color, formula_strategy):
self.natural_level = natural_level
self.desired_level = desired_level
self.desired_tone = desired_tone
self.grey_percentage = grey_percentage
self.coverage_type = coverage_type
self.hair_condition = hair_condition
self.desired_result = desired_result
self.desired_color = desired_color
self.formula_strategy = formula_strategy
self.config = configparser.ConfigParser()
self.config.read('config.ini')
def create_formula(self):
try:
developer = self.formula_strategy.choose_developer(self.natural_level, self.desired_level, self.hair_condition)
grey_coverage_formula = self.formula_strategy.get_grey_coverage_formula(self.grey_percentage)
push_tone = self.formula_strategy.choose_push_tone(self.desired_tone)
formula = f"{developer} {grey_coverage_formula} {push_tone}"
return formula
except Exception as e:
logging.error(f"Error occurred while creating formula: {e}")
return None
# Unit tests
class HairColorFormulaTest(unittest.TestCase):
def test_get_grey_coverage_formula(self):
formula_strategy = DefaultHairColorFormulaStrategy()
expected_formula = "2"
actual_formula = formula_strategy.get_grey_coverage_formula(25)
self.assertEqual(expected_formula, actual_formula)
if __name__ == "__main__":
unittest.main