コード例 #1
0
def mainRender(args):
    #Import this module only in render mode, as it needs pygame and PyOpenGL
    from rendering.renderer import Renderer

    lastUpdate = getCurrentTimeMillis()
    running = True
    loops = 0

    ########
    queue = Manager().Queue()
    killSim = Value('i', 0)
    simProcess = Process(target=simLoop, args=(queue, killSim,))
    simProcess.start()

    random.setSeed(args.seedValue)
    #Initialize the renderer
    initialData = queue.get(block=True)
    numPersons = initialData[0]
    gridSize = initialData[1]
    gridData = initialData[2]
    theRenderer = Renderer(numPersons)
    theRenderer.initPlaceBuffer(gridSize, gridData)
    
    #Get the first simulation datum
    simData = queue.get(block=True)
    simPersons = simData[1]
    simNow = simData[0]
    nowOb = time.Timestamp(simNow)
    ########

    while running:
        now = getCurrentTimeMillis()
        deltaTime = now - lastUpdate

        running = theRenderer.fetchEvents(deltaTime)
        if not queue.empty():
            simData = queue.get(block=False)
            simPersons = simData[1]
            simNow = simData[0]
        theRenderer.render(simPersons, deltaTime, simNow)
        nowOb = time.Timestamp(simNow)
        
        loops += 1
        if loops % 100 == 0:
            print("Simulation time: {0}:{1}:{2}".format(nowOb.day(), nowOb.hourOfDay(), nowOb.minuteOfHour()))

        if args.numDays > 0 and nowOb.day() >= args.numDays:
            running = False

    theRenderer.quit()
    killSim.value = 1
    while(not queue.empty()):
        queue.get(block=False)
    simProcess.join() 
コード例 #2
0
ファイル: simulation.py プロジェクト: KMattis/COVID19Sim
    def __init__(self, persons, grid, diseaseTypes, trafficNetwork):
        self.now = time.Timestamp(time.HOUR * 0)
        self.persons = persons
        self.bobby = persons[0]
        self.grid = grid
        self.lastUpdate = -1
        self.travel = mass_transportation.Travel(persons, trafficNetwork, 2, 4)

        self.diseaseTypes = diseaseTypes

        for disease in self.bobby.diseases.values():
            disease.infect(time.Timestamp(-3 * time.DAY))

        for thePerson in self.persons:
            self.plan(thePerson)
コード例 #3
0
ファイル: disease_types.py プロジェクト: KMattis/COVID19Sim
    def update(self, now, person):
        disease = person.diseases[self]

        if not disease.isInfected:
            return

        infTime = time.Timestamp(now.now() - disease.infectionStarted).day()

        if 3 <= infTime < 12:
            disease.contLevel = 0.5
            disease.contRadius = 1
            disease.healthDamage = 50
            person.needs[self.health] += (simulation.SIMULATION_TICK_LENGTH /
                                          time.HOUR) * 0.1
        #elif 2 <= infTime < 5:
        #    disease.contLevel = 0.8
        #    disease.contRadius = 1
        #    disease.healthDamage = 20
        #elif 5 <= infTime < 7:
        #    disease.contLevel = 1
        #    disease.contRadius = 1.5
        #    disease.healthDamage = 50
        #elif 7 <= infTime < 10:
        #    disease.contLevel = 0.4
        #    disease.contRadius = 0.5
        #    disease.healthDamage = 20
        elif 12 <= infTime:
            disease.contLevel = 0
            disease.contRadius = 0
            disease.healthDamage = 0
            disease.isInfected = False
            disease.isImmune = True
コード例 #4
0
    def drawTime(self, nowmin):
        shader = text.get_default_shader()

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        self.fps_text.set_text('FPS: {0}'.format(round(self.clock.get_fps())))
        now = time.Timestamp(nowmin)
        self.time_text.set_text('{0}:{1}:{2}'.format(round(now.day()),
                                                     round(now.hourOfDay()),
                                                     round(
                                                         now.minuteOfHour())))

        self.fps_text.draw(shader)
        self.time_text.draw(shader)

        glDisable(GL_BLEND)
コード例 #5
0
ファイル: tests.py プロジェクト: KMattis/COVID19Sim
 def test_day(self):
     t = time.Timestamp(1440)
     self.assertEqual(t.day(), 1)
コード例 #6
0
ファイル: tests.py プロジェクト: KMattis/COVID19Sim
 def test_today(self):
     t = time.Timestamp(65 * time.HOUR)
     self.assertEqual(t.today(), 2 * time.DAY)
コード例 #7
0
ファイル: tests.py プロジェクト: KMattis/COVID19Sim
 def test_dayOfWeek(self):
     t = time.Timestamp(4 * time.DAY + 23 * time.HOUR)
     self.assertEqual(t.dayOfWeek(), 4)
コード例 #8
0
ファイル: tests.py プロジェクト: KMattis/COVID19Sim
 def test_hourOfDay(self):
     t = time.Timestamp(36 * time.HOUR)
     self.assertEqual(t.hourOfDay(), 12)