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.

worker.py 3.2KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from django.db import models
  2. from django.core.validators import MaxValueValidator, MinValueValidator
  3. import random
  4. from .engineeringmodel import EngineeringModel, ModelChaotic
  5. from .attributeset import AttributeSet
  6. from .names import WorkerNames
  7. # worker klasse
  8. class Worker(models.Model):
  9. name = models.CharField(default="random worker", max_length=20)
  10. attributes = models.ForeignKey(AttributeSet, default=1, on_delete=models.CASCADE)
  11. skilledModels = models.ForeignKey(
  12. EngineeringModel, on_delete=models.CASCADE, blank=True
  13. )
  14. amplifyer = models.FloatField(
  15. default=1, validators=[MinValueValidator(1.0), MaxValueValidator(2.0)]
  16. )
  17. salary = models.IntegerField(default=1000)
  18. status = models.IntegerField(
  19. default=0, validators=[MinValueValidator(0), MaxValueValidator(3)]
  20. )
  21. # status 0 = in workermarket; 1=in company; 2=wokring on order; 3=locked
  22. lockedRounds = models.IntegerField(default=0, validators=[MinValueValidator(0)])
  23. happyness = models.IntegerField(
  24. default=100, validators=[MinValueValidator(0), MaxValueValidator(100)]
  25. )
  26. sick = models.BooleanField(default=False)
  27. def __str__(self):
  28. return self.name
  29. @classmethod
  30. def createRandom(cls):
  31. name = random.choice(WorkerNames.objects.all()).name
  32. attributes = AttributeSet.createRandom(20)
  33. allmodels = EngineeringModel.objects.all()
  34. allmodelsnochaotic = [
  35. model for model in allmodels if not isinstance(model, ModelChaotic)
  36. ]
  37. skilledModels = random.choice(allmodelsnochaotic)
  38. if random.random() < 0.8:
  39. value = round(random.uniform(1, 1.3), 1)
  40. else:
  41. value = round(random.uniform(1.3, 1.6), 1)
  42. amplifyer = value
  43. salary = round(amplifyer * 2500 * random.uniform(0.7, 1.3))
  44. worker = cls(
  45. name=name,
  46. attributes=attributes,
  47. skilledModels=skilledModels,
  48. amplifyer=amplifyer,
  49. salary=salary,
  50. status=0,
  51. )
  52. worker.save()
  53. return worker
  54. def improveAttribute(self, attribute, amount):
  55. self.attributes.increase(attribute=attribute, amount=amount)
  56. def calculateHappyness(self, number):
  57. if (self.happyness + number) > 100:
  58. self.happyness = 100
  59. elif (self.happyness + number) < 0:
  60. self.happyness = 0
  61. else:
  62. self.happyness += number
  63. self.save()
  64. def quitJob(self):
  65. self.delete()
  66. def calculateSick(self):
  67. if self.sick == False:
  68. randnumber = random.randint(1, 100)
  69. if randnumber <= 3:
  70. self.setStatus(3)
  71. self.setSick(True)
  72. rounds = random.randint(1, 2)
  73. self.setLockedRounds(rounds)
  74. elif self.sick == True and self.lockedRounds < 0:
  75. self.setSick(False)
  76. self.setStatus(1)
  77. def setStatus(self, status):
  78. self.status = status
  79. self.save()
  80. def getStatus(self):
  81. return self.status
  82. def setLockedRounds(self, amount):
  83. self.lockedRounds = amount
  84. self.save()
  85. def setSick(self, sickness):
  86. self.sick = sickness
  87. self.save()