def get(self):  # get stock status
     global Ordertime
     T0 = Ordertime
     parser.add_argument("day of status")
     args = parser.parse_args()
     T = int(args["day of status"])
     milk2, wol2, _, _ = Yak.Stockstatus(Herd, T)
     milk1, wol1, _, _ = Yak.Stockstatus(Herd, T0)
     milk = milk2 - milk1  # netto production with respect to the last order
     wol = wol2 - wol1
     NewStock = {
         "milk": round(OldStock["milk"] + float(milk), 2),
         "skins": OldStock["skins"] + int(wol)
     }
     return (jsonify(NewStock))
Exemplo n.º 2
0
 def test_Stockstatus4(self):  # boundary condition test: yaks below age 1 and some are male
     A1 = [1167.24, 0]
     A2 = [0.62, 0.52, 0.42]
     Herd = []
     age = [0.5, 0.4, 0.3]
     sex = ['f', 'm', 'f']
     for a, s in zip(age, sex):
         NewYak = yak()
         NewYak.age = a
         NewYak.sex = s
         Herd.append(NewYak)
     for i in range(3):
         if i == 2:
             for j in range(3):
                 self.assertAlmostEqual(Yak.Stockstatus(Herd, 12)[2][i], A2[i], places=2)
         else:
             self.assertAlmostEqual(Yak.Stockstatus(Herd, 12)[i], A1[i], places=2)
Exemplo n.º 3
0
 def test_Stockstatus3(self):  # boundary condition test: starting with dead yaks
     A1 = [0, 0]
     A2 = [10, 10, 10]
     Herd = []
     age = [10, 10, 10]
     sex = ['f', 'f', 'f']
     for a, s in zip(age, sex):
         NewYak = yak()
         NewYak.age = a
         NewYak.sex = s
         Herd.append(NewYak)
     for i in range(3):
         if i == 2:
             for j in range(3):
                 self.assertAlmostEqual(Yak.Stockstatus(Herd, 12)[2][i], A2[i], places=2)
         else:
             self.assertAlmostEqual(Yak.Stockstatus(Herd, 0)[i], A1[i], places=2)
 def get(self, T):
     T = int(T)
     [milk, wol, age, age_shave] = Yak.Stockstatus(Herd, T)
     N = len(age)
     data = {"herd": []}
     for i in range(N):
         data["herd"].append({
             "name": Herd[i].name,
             "age": round(age[i], 2),
             "age-last-shaved": round(age_shave[i], 2)
         })
     return (jsonify(data))
 def post(self):  # post order
     parser.add_argument("customer")
     parser.add_argument("milk")
     parser.add_argument("skins")
     parser.add_argument("day of order")
     args = parser.parse_args()
     T = int(args["day of order"])
     global Ordertime
     T0 = Ordertime
     milk2, wol2, _, _ = Yak.Stockstatus(Herd, T)
     milk1, wol1, _, _ = Yak.Stockstatus(Herd, T0)
     milk = milk2 - milk1  #netto production with respect to the last order
     wol = wol2 - wol1
     Ordertime = T
     NewStock = {
         "milk": OldStock["milk"] + float(milk),
         "skins": OldStock["skins"] + int(wol)
     }
     args["milk"] = float(args["milk"])
     args["skins"] = int(args["skins"])
     if NewStock["milk"] >= args["milk"] and NewStock["skins"] >= args[
             "skins"]:
         OldStock["milk"] = NewStock["milk"] - args["milk"]
         OldStock["skins"] = NewStock["skins"] - args["skins"]
         return 201
     if NewStock["milk"] >= args["milk"] or NewStock["skins"] >= args[
             "skins"]:
         if NewStock["milk"] >= args["milk"]:
             OldStock["milk"] = NewStock["milk"] - args["milk"]
             OldStock["skins"] = NewStock["skins"]
             return ({"milk:": args["milk"]}), 206
         else:
             OldStock["milk"] = NewStock["milk"]
             OldStock["skins"] = NewStock["skins"] - args["skins"]
             return ({"skins:": args["skins"]}), 206
     else:
         OldStock["milk"] = NewStock["milk"]
         OldStock["skins"] = NewStock["skins"]
         return 404
Exemplo n.º 6
0
 def test_Stockstatus(self):  # assignment examples
     Herd = []
     age = [4, 8, 9.5]
     sex = ['f', 'f', 'f']
     for a,s in zip(age,sex):
         NewYak = yak()
         NewYak.age = a
         NewYak.sex = s
         Herd.append(NewYak)
     for T in [13,14]:
         if T == 13:
             A1 = [1104.48, 3]
             A2 = [4.13, 8.13, 9.63]
         else:
             A1 = [1188.81, 4]
             A2 = [4.14, 8.14, 9.64]
         for i in range(3):
             if i == 2:
                 for j in range(3):
                     self.assertAlmostEqual(Yak.Stockstatus(Herd, T)[2][i], A2[i], places=2)
             else:
                 self.assertAlmostEqual(Yak.Stockstatus(Herd, T)[i], A1[i], places=2)
Exemplo n.º 7
0
from xml.etree import ElementTree as ET
import Yak
from Yak import yak
file_name = 'herd.xml'
tree = ET.parse(file_name)
root = tree.getroot()
Herd = []
for child in root:
    NewYak = yak()
    NewYak.name = child.attrib['name']
    NewYak.age = float(child.attrib['age'])
    NewYak.sex = child.attrib['sex']
    Herd.append(NewYak)
[milk, wol, age, age_shave] = Yak.Stockstatus(Herd, 13)
N = len(Herd)
print('In Stock:\n ' f'{"%.2f" % milk} liter of milk\n {wol} skins of wool')
print('Herd:')
for i in range(N):
    if age[i] >= 10:
        print(f'{Herd[i].name} is dead')
    else:
        print(f'{Herd[i].name} is {"%.2f" %age[i]} years old')