예제 #1
0
    def __init__(self, file, plugin_path, ttl):
        self.file = file                     # linux/cpu.sh
        self.name = file.rpartition('/')[2]  # cpu.sh

        self.plugin_path = plugin_path

        self.running = False
        self.logger = logging.getLogger('default')
        self.datastore = datastore.datastore(ttl)

        # Set default values
        self.interval = 10

        # Create thread with timer
        self.t = Timer(self.interval, self.execute)
예제 #2
0
def mainThread():
  global event
  global dataLight
  global dataTemp
  global threadRun
  global threadCount
  print "Main thread starting..."
  subprocess.call(['modprobe','w1-gpio'])
  subprocess.call(['modprobe','w1-therm'])
  threadCount = threadCount + 1
  boxStore = datastore.datastore('./birdbox.db')
  if os.path.isfile('./birdbox.db'):
    print "Have database file using it..."
  else:
    #Create new table structure in above database   
    boxStore.createNewStore()

  while threadRun:
    if (event == 1):
      print "Store entry"
      boxStore.registerEntry()
      event = 0
      #tweet activity
      twt = tweeter.tweetit()
      print "Send Entry Tweet"
      twt.door("Entry")

    if (event == 2):
     print "Store exit"
     boxStore.registerExit()
     event = 0
     #tweet activity
     twt = tweeter.tweetit()
     print "Send Exit tweet"
     twt.door("Exit")
    if (event == 3):
      print "Store light value:" + str(dataLight)
      boxStore.registerLight(dataLight)
      event = 0
    if (event == 4):
      print "Store temp value:" + str(dataTemp)
      boxStore.registerTemp(dataTemp)
      event = 0
  threadCount = threadCount - 1
예제 #3
0
def mainThread():
    global event
    global dataLight
    global dataTemp
    global threadRun
    global threadCount
    print "Main thread starting..."
    subprocess.call(['modprobe', 'w1-gpio'])
    subprocess.call(['modprobe', 'w1-therm'])
    threadCount = threadCount + 1
    boxStore = datastore.datastore('./birdbox.db')
    if os.path.isfile('./birdbox.db'):
        print "Have database file using it..."
    else:
        #Create new table structure in above database
        boxStore.createNewStore()

    while threadRun:
        if (event == 1):
            print "Store entry"
            boxStore.registerEntry()
            event = 0
            #tweet activity
            twt = tweeter.tweetit()
            print "Send Entry Tweet"
            twt.door("Entry")

        if (event == 2):
            print "Store exit"
            boxStore.registerExit()
            event = 0
            #tweet activity
            twt = tweeter.tweetit()
            print "Send Exit tweet"
            twt.door("Exit")
        if (event == 3):
            print "Store light value:" + str(dataLight)
            boxStore.registerLight(dataLight)
            event = 0
        if (event == 4):
            print "Store temp value:" + str(dataTemp)
            boxStore.registerTemp(dataTemp)
            event = 0
    threadCount = threadCount - 1
예제 #4
0
from parse import parsejson
from httprequests import httprequests
from datastore import datastore
from folder import folder
import datetime
'''
Quick and dirty hack by stephen to add cc to course capture videos
Need to add better error handling
'''
if __name__ == "__main__":
  print "Starting..."
  config = parsejson()
  db = datastore()
  db.loadtables()
  myrequests = httprequests(config.config)
  myrequests.login()
  try:
      while 1:
          for k,p in config.dirs.iteritems():
              #print p
              f = folder(p)
              f.load()
              db.addnew(f.hasvideo())
              pending = db.getallpending()
              #myrequests.createjob()
              for pend in pending:
                  print p
                  print "-----"
                  info = myrequests.createjob()
                  print pend[2]
                  r = myrequests.addmedia(pend[2],info['jobid'])
예제 #5
0
파일: batch.py 프로젝트: amrith1/CommNets
PICKY = args.pickiness
RATE = args.rate
MAX_TIME = args.max_time
BATCH_TIME = args.parameter

# constant
BOY = 0
GIRL = 1
A_TIME = 0
SCORE = 1
GENDER = 2

data = datastore("batch",
                 BATCH_TIME,
                 HASTE,
                 PICKY,
                 RATE,
                 MAX_TIME,
                 time_store=int(MAX_TIME / BATCH_TIME))

boys = []
girls = []
dump = []
dump_gender = BOY


def arrival_generator():
    last_arrival_time = 0
    while True:
        last_arrival_time = last_arrival_time + rand.exponential(scale=1 /
                                                                 RATE)
예제 #6
0
THRESHOLD = args.parameter

# constant
BOY = 0
GIRL = 1
A_TIME = 0
SCORE = 1
GENDER = 2

asd
kaSDK

data = datastore("threshold",
                 THRESHOLD,
                 HASTE,
                 PICKY,
                 RATE,
                 MAX_TIME,
                 time_store=1000)


def arrival_generator():
    last_arrival_time = 0
    while True:
        last_arrival_time = last_arrival_time + rand.exponential(scale=1 /
                                                                 RATE)
        yield last_arrival_time, rand.uniform(), rand.randint(
            2)  # Atime, Score, Gender


arrival = arrival_generator()
예제 #7
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--haste', help='', default=None, type=float)
    parser.add_argument('--pickiness', help='', default=None, type=float)
    parser.add_argument('--rate', help='', default=None, type=float)
    parser.add_argument('--max_time', help='', default=None, type=float)
    parser.add_argument('--parameter', help='', default=None, type=float)
    args = parser.parse_args()

    HASTE = args.haste
    PICKY = args.pickiness
    RATE = args.rate
    MAX_TIME = args.max_time
    THRESHOLD = args.parameter

    # constant
    BOY = 0
    GIRL = 1
    A_TIME = 0
    SCORE = 1
    GENDER = 2

    data = datastore("time_threshold",
                     THRESHOLD,
                     HASTE,
                     PICKY,
                     RATE,
                     MAX_TIME,
                     time_store=1000)

    def arrival_generator():
        last_arrival_time = 0
        while True:
            last_arrival_time = last_arrival_time + rand.exponential(scale=1 /
                                                                     RATE)
            yield last_arrival_time, rand.uniform(), rand.randint(
                2)  # Atime, Score, Gender

    arrival = arrival_generator()
    boys_scores = []
    girls_scores = []
    boys_atime = []
    girls_atime = []

    current_time = 0
    while current_time < MAX_TIME:
        #print(current_time, end="\r")
        candidate = next(arrival)
        current_time = candidate[A_TIME]
        if current_time < MAX_TIME:
            data.add_time_stat(len(boys_scores), len(girls_scores),
                               current_time)

        match_atime = boys_atime if candidate[GENDER] is GIRL else girls_atime
        match_scores = boys_scores if candidate[
            GENDER] is GIRL else girls_scores
        competitors_atime = boys_atime if candidate[
            GENDER] is BOY else girls_atime
        competitor_scores = boys_scores if candidate[
            GENDER] is BOY else girls_scores

        low_index = bisect_left(match_scores, candidate[SCORE] - THRESHOLD)
        high_index = bisect_left(match_scores, candidate[SCORE] + THRESHOLD)

        def queue_candidate():
            insert_loc = bisect_left(competitor_scores, candidate[SCORE])
            competitors_atime.insert(insert_loc, candidate[A_TIME])
            competitor_scores.insert(insert_loc, candidate[SCORE])

        if high_index - low_index > 0 and high_index != 0:
            potential_match_atime = np.array(match_atime[low_index:high_index])
            match_index = low_index + np.argmax(potential_match_atime)
            match = (match_atime.pop(match_index),
                     match_scores.pop(match_index), 1 ^ candidate[GENDER])
            data.add_match(candidate, match, current_time)
        else:
            queue_candidate()
    print("Saving")
    data.save_stranglers(boys_scores, girls_scores, boys_atime, girls_atime)
    data.save_stats()