<commit_before>#! /usr/bin/env python

""" lab_simulator.py - A script for simulating logins/logouts in a labtracker lab for testing purposes.
"""

from client_scripts import tracker

import settings
from django.core.management import setup_environ

setup_environ(settings)

from labtracker.Machine.models import Item, Status

import datetime
import random
import time

tracker.DEBUG = True
tracker.NO_SSL = True
LABTRACKER_URL = 'walnut.eplt.washington.edu:8000'

inuse = Status.objects.get(name='Inuse')

def sim_login_or_logout(item):
    if item.status.get(name='Usable'):
        try:
            item.status.get(name='Inuse')
            item.status.remove(inuse)
            print "Logging out %s" % item
            tracker._track(LABTRACKER_URL, 'logout', item.mac1)
        except:
            item.status.add(inuse)
            print "Logging in %s" % item
            tracker._track(LABTRACKER_URL, 'login', item.mac1)

def main():
    items = Item.objects.all()

    while 1:
        item = Item.objects.get(item_id=random.randrange(1,items.count()))
        sim_login_or_logout(item)
        delay = random.randrange(1,(5460/items.count()))
        time.sleep(delay)

if __name__ == "__main__":
    main()<commit_msg>Updated lab simulator to use the new Unusable flag.<commit_after>#! /usr/bin/env python

""" lab_simulator.py - A script for simulating logins/logouts in a labtracker lab for testing purposes.
"""

from client_scripts import tracker

import settings
from django.core.management import setup_environ

setup_environ(settings)

from labtracker.Machine.models import Item, Status

import datetime
import random
import time

tracker.DEBUG = True
tracker.NO_SSL = True
LABTRACKER_URL = 'walnut.eplt.washington.edu:8000'

inuse = Status.objects.get(name='Inuse')

def sim_login_or_logout(item):
    if not item.unusable:
        try:
            item.status.get(name='Inuse')
            item.status.remove(inuse)
            print "Logging out %s" % item
            tracker._track(LABTRACKER_URL, 'logout', item.mac1)
        except:
            item.status.add(inuse)
            print "Logging in %s" % item
            tracker._track(LABTRACKER_URL, 'login', item.mac1)
    else:
        print "%s is unusable" % item

def main():
    items = Item.objects.all()

    while 1:
        item = Item.objects.get(item_id=random.randrange(1,items.count()))
        sim_login_or_logout(item)
        delay = random.randrange(1,(5460/items.count()))
        time.sleep(delay)

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.11124260355029586, 'fraction_numerical': 0.010256410256410256, 'mean_word_length': 3.044657097288676, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2707787', 'n_tokens_mistral': 837, 'n_tokens_neox': 821, 'n_words': 188}