File size: 2,995 Bytes
6f2393d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57ba992
6f2393d
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import logging
import time
from abc import ABC


class AbstractPump:

    def __init__(self, com_port: str):
        self.com_port = com_port
        self.dictionary = {}
        self.logger = logging.getLogger("pump")

    def dose_liquid(self, amount_in_ml: float, rate_ml_per_minute: float = 1):
        """dose liquid"""
        self.logger.info("dosing liquid")
        self.logger.info(f"pretending dosing {amount_in_ml} at {rate_ml_per_minute} ml/min")
        return 1



class AbstractBalance:

    def __init__(self, com_port: str):
        self.com_port = com_port
        self._value = None
        self.logger = logging.getLogger("balance")

    @property
    def setter_value(self):
        return self._value

    @setter_value.setter
    def setter_value(self, value):
        self._value = value

    def weigh_sample(self):
        time.sleep(1)
        self.logger.info(f"Weighing sample using {self.com_port}")
        return 1

    def dose_solid(self, amount_in_mg: float):
        """this function is used to dose solid"""
        time.sleep(1)
        self.logger.info(f"Dosing {amount_in_mg} mg using {self.com_port}")
        return 1

    def _helper(self):
        """helper function will not be extracted and displayed over function panel"""
        pass




class AbstractSDL(ABC):
    def __init__(self, pump: AbstractPump, balance: AbstractBalance):
        self.pump = pump
        self.balance = balance
        self.logger = logging.getLogger(f"logger_name")

    def analyze(self):
        self.logger.info("analyze")
        time.sleep(1)
        return 1


    def dose_solid(self,
                   amount_in_mg: float = 5,
                   solid_name: str = "Acetaminophen"
                   ):
        """dose current chemical"""
        print("dosing solid")
        self.balance.dose_solid(amount_in_mg=amount_in_mg)
        self.balance.weigh_sample()
        time.sleep(1)
        self.logger.info(f"dosing solid {amount_in_mg} mg of {solid_name}")
        return 1

    def dose_solvent(self,
                     solvent_name: str = "Methanol",
                     amount_in_ml: float = 5,
                     rate_ml_per_minute: float = 1
                     ):
        print("dosing liquid")
        self.logger.info(f"dosing {amount_in_ml} ml of {solvent_name} solvent at {rate_ml_per_minute} ml/min")
        time.sleep(1)
        return 1


    def equilibrate(self,
                    temp: float,
                    duration: float
                    ):
        print("equilibrate")
        self.logger.info(f"equilibrate at {temp} for {duration}")
        time.sleep(1)

    def simulate_error(self):
        raise ValueError("some error")

    def _send_command(self):
        """helper function"""
        pass



# initializing hardware
balance = AbstractBalance("Fake com port 1")
pump = AbstractPump("Fake com port 2")
sdl = AbstractSDL(pump, balance)


if __name__ == "__main__":
    import ivoryos
    ivoryos.run(__name__)