Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. from django.db import models
  2. from django.core.validators import MaxValueValidator, MinValueValidator
  3. from polymorphic.models import PolymorphicModel
  4. from .engineeringmodel import EngineeringModel
  5. import random
  6. # Event und erbende Klassen (specialOrder)
  7. class Event(PolymorphicModel):
  8. name = models.CharField(default="random Event", max_length=40)
  9. description = models.CharField(default="Event description here", max_length=200)
  10. @classmethod
  11. def createEmpty(cls):
  12. emptyEvent = cls(
  13. name="Your E-Mails are empty",
  14. description="You do not have E-Mails this round.",
  15. )
  16. emptyEvent.save()
  17. return emptyEvent
  18. @classmethod
  19. def createOrderFailed(cls, ordername):
  20. name = ordername + " canceled."
  21. description = (
  22. "Your order "
  23. + ordername
  24. + " ran out of rounds! The order was canceled and your customerSatisfaction decreased."
  25. )
  26. event = cls(
  27. name=name,
  28. description=description,
  29. )
  30. event.save()
  31. return event
  32. @classmethod
  33. def createOrderFinished(cls, ordername, profit):
  34. name = ordername + " finished."
  35. description = (
  36. "Your order "
  37. + ordername
  38. + " was completed! The profit of "
  39. + profit
  40. + " was added to your companys money."
  41. )
  42. event = cls(
  43. name=name,
  44. description=description,
  45. )
  46. event.save()
  47. return event
  48. @classmethod
  49. def createWorkerQuit(cls, threshhold, workername, workerhappyness):
  50. name = workername + " quit his job."
  51. description = (
  52. "Your worker "
  53. + workername
  54. + " quit his job due to his happyness falling to "
  55. + str(workerhappyness)
  56. + "! Falling below "
  57. + str(threshhold)
  58. + " will result in increasing chance for your worker to quit!"
  59. )
  60. event = cls(
  61. name=name,
  62. description=description,
  63. )
  64. event.save()
  65. return event
  66. @classmethod
  67. def createSpecialOrderPenalty(cls, order):
  68. name = "You ignored the Special Order for " + order.name
  69. description = (
  70. "You ignored the Special Order for the order "
  71. + order.name
  72. + ". Penalties have been applied! [-20 Customer Satisfaction; -20% Profit]"
  73. )
  74. event = cls(
  75. name=name,
  76. description=description,
  77. )
  78. event.save()
  79. return event
  80. @classmethod
  81. def createSpecialOrderBonus(cls, order):
  82. name = "You handled the Special Order for " + order.name
  83. description = (
  84. "You handled the Special Order for the order "
  85. + order.name
  86. + " in a flexible model. You received a bonus on your order!"
  87. + " [+10 Customer Satisfaction; +10 Worker Satisfaction; +20% Profit ; +10 happyness all Workers]"
  88. )
  89. event = cls(
  90. name=name,
  91. description=description,
  92. )
  93. event.save()
  94. return event
  95. @classmethod
  96. def createSpecialOrderWrongModel(cls, order):
  97. name = "You handled the Special Order for " + order.name
  98. description = (
  99. "You handled the Special Order for the order "
  100. + order.name
  101. + ", but you are working with an unflexible model! You let your workers work overtime to complete the customers wish."
  102. + " [+30 Workload on all Skills; -20 happyness all Workers; -10 Worker Satsifaction]"
  103. )
  104. event = cls(
  105. name=name,
  106. description=description,
  107. )
  108. event.save()
  109. return event
  110. class EventOfferAccepted(Event):
  111. order = models.ForeignKey("Order", default=1, on_delete=models.CASCADE)
  112. modelset = models.BooleanField(default=False)
  113. def setModel(self, model):
  114. self.order.setEngineeringmodel(model)
  115. self.modelset = True
  116. self.save()
  117. class SpecialOrder(Event):
  118. occuranceProbability = models.IntegerField(
  119. default=100, validators=[MinValueValidator(0), MaxValueValidator(100)]
  120. )
  121. validModels = models.ManyToManyField(EngineeringModel, blank=True)
  122. occured = models.BooleanField(default=False)
  123. hint = models.CharField(default="no hint", max_length=100)
  124. def getValidModels(self):
  125. vmodels = []
  126. for model in self.validModels.all():
  127. vmodels.append(model.name)
  128. return vmodels
  129. def setDefaultValidModels(self):
  130. self.validModels.add(EngineeringModel.objects.get(name="ModelScrum"))
  131. self.validModels.add(EngineeringModel.objects.get(name="ModelSpiral"))
  132. self.validModels.add(EngineeringModel.objects.get(name="ModelHeyJoe"))
  133. def createHint(occuranceProbability):
  134. if occuranceProbability <= 10:
  135. hintlist = [
  136. "The project is discussed completely from the beginning, and clear agreements are made regarding the requirements and scope of the project.",
  137. "The customer is known to wish little interaction with its project partners and just wants to get the job done.",
  138. "A tight budget and strict time management allows little changes within the project.",
  139. "The company has emphasized the importance of precise planning and scope definition, indicating their intention to avoid unnecessary changes.",
  140. "The client's primary focus is on efficiency and timely completion, suggesting they are unlikely to introduce substantial changes mid-project.",
  141. "With a fixed project scope and well-defined milestones, the company seems committed to maintaining project stability.",
  142. "Previous collaborations with the company reveal a preference for minimal modifications during the project execution phase.",
  143. ]
  144. else:
  145. hintlist = [
  146. "Previous project collaborations with the firm have involved multiple change requests and additional features added throughout the development process.",
  147. "The client has expressed a strong desire for flexibility and creativity in the project execution.",
  148. "Given the dynamic nature of the industry they work in, it is likely that the company will request modifications to adapt to emerging trends.",
  149. "The client has not yet finalized their longterm strategy, which means changes and updates to the project might be needed.",
  150. "The company regularely takes user feedback, which might demand project alteration and updating.",
  151. "The client has expressed an interest in prototyping certain features to explore different possibilities, which may result in the addition of new requirements.",
  152. "The customer wishes for an agile project execution to have the option to get involved in the projects development.",
  153. ]
  154. hint = random.choice(hintlist)
  155. return hint
  156. def calculateOccurance(self):
  157. randnum = random.randint(1, 100)
  158. if (self.occuranceProbability >= randnum) and not self.occured:
  159. return True
  160. else:
  161. return False
  162. def createOccuranceProbability():
  163. # 50% chance dass es relativ wahrscheinlich/unwahrscheinlich ist das SO auftritt
  164. randnum = random.randint(1, 2)
  165. if randnum == 1:
  166. # niedrige OP
  167. occuranceProbability = random.randint(1, 5)
  168. else:
  169. # hohe OP
  170. occuranceProbability = random.randint(30, 40)
  171. return occuranceProbability
  172. def occure(self, company):
  173. if self.calculateOccurance():
  174. company.events.add(self)
  175. self.occured = True
  176. self.save()
  177. def handle(self, order, company, handle):
  178. if order.engineeringModel.name in self.getValidModels():
  179. self.bonus(order, company)
  180. event = Event.createSpecialOrderBonus(order)
  181. elif handle == True:
  182. self.invest(order, company)
  183. event = Event.createSpecialOrderWrongModel(order)
  184. else:
  185. self.penalty(order, company)
  186. event = Event.createSpecialOrderPenalty(order)
  187. company.events.remove(self)
  188. company.events.add(event)
  189. return event
  190. def bonus(self, order, company):
  191. company.calculateCustomerSatisfaction(20)
  192. company.calculateWorkerSatisfaction(10)
  193. order.profit *= 1.2
  194. for worker in company.workers.all():
  195. worker.calculateHappyness(10)
  196. order.save()
  197. company.save()
  198. def penalty(self, order, company):
  199. company.calculateCustomerSatisfaction(-20)
  200. order.profit *= 0.8
  201. order.save()
  202. company.save()
  203. def invest(self, order, company):
  204. order.addWorkload(30)
  205. for worker in company.workers.all():
  206. worker.calculateHappyness(-20)
  207. company.calculateWorkerSatisfaction(-10)
  208. order.save()
  209. company.save()
  210. class SOPrototyp(SpecialOrder):
  211. @classmethod
  212. def createRandom(cls, ordername):
  213. name = "Specialorder prototyp request from " + ordername
  214. description = (
  215. "Your customer for the order "
  216. + ordername
  217. + " wants you to produce a prototyp for them to review."
  218. )
  219. # hier random low <5% per round oder high < 40% per round
  220. occuranceProbability = cls.createOccuranceProbability()
  221. hint = cls.createHint(occuranceProbability=occuranceProbability)
  222. specialorder = cls(
  223. name=name,
  224. description=description,
  225. occuranceProbability=occuranceProbability,
  226. hint=hint,
  227. )
  228. specialorder.save()
  229. specialorder.setDefaultValidModels()
  230. specialorder.save()
  231. return specialorder
  232. class SORegularIncrementUpdates(SpecialOrder):
  233. @classmethod
  234. def createRandom(cls, ordername):
  235. name = "Specialorder regular incremental updates request from " + ordername
  236. description = (
  237. "Your customer for the order "
  238. + ordername
  239. + " wants to get regular updates on the increments of the project!"
  240. )
  241. # hier random low <5% per round oder high < 40% per round
  242. occuranceProbability = cls.createOccuranceProbability()
  243. hint = cls.createHint(occuranceProbability=occuranceProbability)
  244. specialorder = cls(
  245. name=name,
  246. description=description,
  247. occuranceProbability=occuranceProbability,
  248. hint=hint,
  249. )
  250. specialorder.save()
  251. specialorder.setDefaultValidModels()
  252. specialorder.save()
  253. return specialorder
  254. class SOChangeRequirement(SpecialOrder):
  255. @classmethod
  256. def createRandom(cls, ordername):
  257. name = "Specialorder change requirement request from " + ordername
  258. description = (
  259. "Your customer for the order "
  260. + ordername
  261. + " wants to change some requirements on your order. "
  262. )
  263. # hier random low <5% per round oder high < 40% per round
  264. occuranceProbability = cls.createOccuranceProbability()
  265. hint = cls.createHint(occuranceProbability=occuranceProbability)
  266. specialorder = cls(
  267. name=name,
  268. description=description,
  269. occuranceProbability=occuranceProbability,
  270. hint=hint,
  271. )
  272. specialorder.save()
  273. specialorder.setDefaultValidModels()
  274. specialorder.save()
  275. return specialorder