fixed rookie mistakes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2021-12-03 22:31:33 +01:00
parent 35a68fe549
commit a9f473e2d9
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
8 changed files with 100 additions and 28 deletions

View File

@ -1,8 +1,10 @@
class ApplicationModule:
bwRequirement: int = 0
cpuRequirement: int = 0
def __init__(self):
self.bwRequirement: int = 0
self.cpuRequirement: int = 0
class Application:
name: str = ""
modules: list[ApplicationModule] = []
def __init__(self):
self.name: str = ""
self.modules: list[ApplicationModule] = []

View File

@ -7,9 +7,10 @@ class BucketResourceType(Enum):
class BucketResource:
type: BucketResourceType = BucketResourceType.NetworkLink
currentUsage: int = 0
capacity: int = 0
def __init__(self):
self.type: BucketResourceType = BucketResourceType.NetworkLink
self.currentUsage: int = 0
self.capacity: int = 0
def reserve(self, resource: int) -> bool:
if self.capacity == self.currentUsage or resource > self.capacity - self.currentUsage:

View File

@ -2,6 +2,7 @@ from apps import Application
class Client:
startSlices: list[int] = []
lengthOfTransmission: int = 0
application: Application = Application()
def __init__(self):
self.startSlices: list[int] = []
self.lengthOfTransmission:int = 0
self.application: Application = Application()

View File

@ -2,5 +2,6 @@ from bucketresources import BucketResource
class Datacentre:
processingpower: BucketResource = BucketResource()
uplink: BucketResource = BucketResource()
def __init__(self):
self.processingpower: BucketResource = BucketResource()
self.uplink: BucketResource = BucketResource()

View File

@ -1,16 +1,17 @@
# This is a sample Python script.
from pprint import pprint
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from scenarioplanner import Scenarioplanner
from src import scenarioplanner
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def preparesimulation() -> Scenarioplanner:
scenarioplanner = Scenarioplanner()
scenarioplanner.simulationLength = 120
scenarioplanner.createapplications()
scenarioplanner.createclients(1000)
return scenarioplanner
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
scenarioplanner = preparesimulation()
pprint(scenarioplanner)

62
src/scenarioplanner.py Normal file
View File

@ -0,0 +1,62 @@
import random
from clients import Client
from stats import Stats
from apps import Application, ApplicationModule
class Scenarioplanner:
def __init__(self):
self.clients: list[Client] = []
self.applications: list[Application] = []
self.statsModule: Stats = Stats()
self.simulationLength: int = 0
self.maxLengthofTransmission: int = 60
def createbirbnetes(self) -> Application:
birbnetes = Application()
birbnetes.name = 'birbnetes'
edgemodule = ApplicationModule()
edgemodule.bwRequirement = 8800
edgemodule.cpuRequirement = 1000
cloudmodule = ApplicationModule()
cloudmodule.bwRequirement = 10000
cloudmodule.cpuRequirement = 10000
birbnetes.modules.append(edgemodule)
birbnetes.modules.append(cloudmodule)
return birbnetes
def createvideoChat(self) -> Application:
videochat = Application()
videochat.name = 'videochat'
edgemodule = ApplicationModule()
edgemodule.bwRequirement = 90000
edgemodule.cpuRequirement = 10
cloudmodule = ApplicationModule()
cloudmodule.bwRequirement = 90000
cloudmodule.cpuRequirement = 10
videochat.modules.append(edgemodule)
videochat.modules.append(cloudmodule)
return videochat
def createapplications(self) -> None:
self.applications.append(self.createbirbnetes())
self.applications.append(self.createvideoChat())
def pickapplicationforclient(self) -> Application:
chosenapplication = random.choice(self.applications)
if chosenapplication.name == 'birbnetes':
self.statsModule.birbnetesClients += 1
else:
if chosenapplication.name == 'videochat':
self.statsModule.videochatClients += 1
return chosenapplication
def createclients(self, numofclients: int = 1) -> None:
for i in range(numofclients):
currentclient: Client = Client()
currentclient.lengthOfTransmission = random.randint(1, self.maxLengthofTransmission)
numoftransmissions: int = random.randint(1, 10)
for j in range(numoftransmissions):
currentclient.startSlices.append(
random.randint(1, self.simulationLength - self.maxLengthofTransmission))
self.clients.append(currentclient)

View File

@ -5,9 +5,7 @@ from datacentre import Datacentre
class Scheduler:
clients: list[Client] = []
cloud: Datacentre = Datacentre()
edge: Datacentre = Datacentre()
def createClients(self, numofClients: int = 1):
pass
def __init__(self):
self.clients: list[Client] = []
self.cloud: Datacentre = Datacentre()
self.edge: Datacentre = Datacentre()

6
src/stats.py Normal file
View File

@ -0,0 +1,6 @@
class Stats:
def __init__(self):
self.birbnetesClients:int = 0
self.videochatClients:int = 0
self.failedReqsuests:int = 0
self.failedDetails:dict = {}