Beispiel #1
0
def main():
	event_queue = EventQueue(['slot_end', 'weight_change', 'pill_change', 'presc_man', 'timeslot', 'alert', 'new_pres', 'timer','slot_begin'])
	prescription_manager = PrescriptionManager(event_queue)	
	inventory_manager = InventoryManager(event_queue)
	timer = Timer(event_queue)

	anomaly = Anomaly(inventory_manager, prescription_manager, event_queue)
	notifier = Notifier(event_queue, 'patient')
	print ('All objects created')
	
	prescription = {'id': '1', 'medicines':{'abc':[2, 1, 1, 1, 1, 1, 1, 1], 'def':[2, 2, 1, 2, 1, 1, 2, 1]}, 'expiry_date':'12/11/2018' }
	new_prescription = Event('presc_man', {'type': 'new', 'prescription':prescription})
	event_queue.new_event(new_prescription)
	
	medicines = {'abc': {'pills': 50, 'weight':0.1}, 'def': {'pills': 40, 'weight':0.2} }
	inventory_manager.update_medicines(medicines)
	print ('Initialised all objects')
	print(event_queue._event_queue)
	event_queue.update()
	sleep(1)

	while(True):
		slot_num= input('>>>')
		if slot_num != '-1':
			slot_num = int(slot_num)
			weight = float(input())
			event = Event('weight_change', {'slot': slot_num, 'weight': weight, 'time': get_current_time()})
			event_queue.new_event(event)
		print(event_queue._event_queue)
		#print("In main")
		event_queue.update()
		sleep(60)
Beispiel #2
0
def historical_anomalies(original_df, v_thresh=5, p_thresh=1.25, win_size=120):

    # has changes as ts_interval_begin
    print("win_size historical anomalies is:", win_size)

    v_thresh = float(v_thresh)
    p_thresh = float(p_thresh)
    win_size = int(win_size)

    original_df, pumpdf = analyse_symbol(original_df,
                                         v_thresh,
                                         p_thresh,
                                         win_size,
                                         c_size='1m',
                                         plot=False)

    # get the indices of our pumpdf
    index_first = list(pumpdf.index.values)
    index_list = []
    # print("index first=", index_first)

    # removing "pumps" that are part of same pump section
    ref = 0
    for i, val in enumerate(index_first):
        if i == 0:
            ref = val
            index_list.append(val)
        if val > ref + 60:
            index_list.append(val)
            ref = val
        else:
            continue

    print("index list=", index_list)

    if index_list:
        anom_list = []
        print("new  -------> attempting print: ", index_list)
        for val in index_list:
            anomaly_date = str(original_df.iloc[val]['ts_interval_begin'])
            if (val - 30) < 0:
                data = original_df[val:val + 30]
            elif (val + 30 > len(original_df.index)):
                data = original_df[val - 30:val]
            else:
                data = original_df[val - 30:val + 30][[
                    'ts_interval_begin', 'open', 'high', 'low', 'close',
                    'volume'
                ]]
            data['ts_interval_begin'] = data['ts_interval_begin'].apply(str)
            anom_object = Anomaly(anomaly_date, data.values.tolist())
            anom_list.append(anom_object)
        return anom_list
    else:
        return []
 def _declining_cpu_util(self):
     if not self._is_n_day_data_present(4):
         return False
     ref_val = self.day_wise_averages[self.ref_date]
     for i in range(3):
         _next = self.day_wise_averages[self.ref_date - timedelta(i)]
         _prev = self.day_wise_averages[self.ref_date - timedelta(i + 1)]
         if _next > _prev:
             return False
     self.print_anomaly('declining cpu', ref_val, 0.0)
     return Anomaly('declining cpu', self.dim_val, self.day_wise_averages,
                    self.ref_date)
Beispiel #4
0
def index():
    a = Anomaly()

    testcase = np.array([
        [4, 0, 0.8, 2, 500],
        [0.1, 0, 0.8, 2, 500],
        [4, 0, 0.8, 2, 250],
        [4, 0, 0.8, 2, 550],
    ])

    total = a.get_anomaly(testcase)
    mean = a.get_mean_anomaly(testcase)
    contributer = a.get_largest_contributer(testcase)

    # print("total anomaly:",)
    # print("avg anomaly:",)
    # print("contributer:",a.get_largest_contributer(testcase))

    return "<br/>".join([
        "total anomaly: {0} <br/> mean anomaly: {1} <br/> contributer: {2}".
        format(x, y, z) for x, y, z in zip(total, mean, contributer)
    ])
    def _check_unusually_low_cpu(self):
        if not self._is_n_day_data_present(7):
            return False
        ref_val = self.day_wise_averages[self.ref_date]
        avg_of_last_6_days = self._get_n_day_average(6)

        cond1 = ref_val < 0.5 * avg_of_last_6_days
        cond2 = all([
            ref_val <
            0.7 * self.day_wise_averages[self.ref_date - timedelta(i)]
            for i in range(1, 7)
        ])
        if cond1 and cond2:
            self.print_anomaly('low cpu ', ref_val, avg_of_last_6_days)
            return Anomaly('low cpu', self.dim_val, self.day_wise_averages,
                           self.ref_date)
        return False
    def main(self):

        self.logged_in = False

        self.event_queue = EventQueue([
            'slot_end', 'weight_change', 'pill_change', 'presc_man',
            'timeslot', 'alert', 'new_pres', 'timer', 'slot_begin'
        ])
        self.prescription_manager = PrescriptionManager(self.event_queue)
        self.inventory_manager = InventoryManager(self.event_queue)
        self.timer = Timer(self.event_queue)

        self.anomaly = Anomaly(self.inventory_manager,
                               self.prescription_manager, self.event_queue)

        width = 300
        height = 200
        self.main_wid = tkinter.Tk()

        # Center the window
        self.main_wid.update_idletasks()
        x = (self.main_wid.winfo_screenwidth() // 2) - (width // 2)
        y = (self.main_wid.winfo_screenheight() // 2) - (height // 2)
        self.main_wid.geometry('{}x{}+{}+{}'.format(width, height, x, y))

        # Add title
        self.main_wid.title("IntelligentMedicineBox")
        self.email_wid_label = tkinter.LabelFrame(self.main_wid,
                                                  text="Enter login")
        self.email_wid = tkinter.Entry(self.email_wid_label)
        self.pass_wid_label = tkinter.LabelFrame(self.main_wid,
                                                 text="Enter password")
        self.pass_wid = tkinter.Entry(self.pass_wid_label, show='*')
        self.email_wid_label.pack(anchor='center')
        self.email_wid.pack(anchor='center')
        self.pass_wid_label.pack(anchor='center')
        self.pass_wid.pack(anchor='center')
        self.login_button = tkinter.Button(self.main_wid,
                                           text="Login",
                                           command=self.login_cmd)
        self.login_button.pack(anchor='center')

        self.notifier = Notifier(self.event_queue)

        self.lock = threading.Lock()
        self.running = True
        self.thr = threading.Thread(target=self.mainloop)
        self.thr.start()

        self.label_wid = tkinter.LabelFrame(self.main_wid,
                                            text="Enter Slot Number")

        self.slot_entry_wid = tkinter.Entry(self.label_wid)

        self.slot_entry_wid.focus_set()

        self.new_weight_entry_label = tkinter.LabelFrame(
            self.main_wid, text="Enter New Slot Weight")

        self.weight_entry = tkinter.Entry(self.new_weight_entry_label)
        self.new_weight_entry_label.focus_set()

        self.submit_button = tkinter.Button(self.main_wid,
                                            text="Submit",
                                            command=self.submit_cmd)

        self.main_wid.protocol("WM_DELETE_WINDOW", self.on_closing)

        self.main_wid.mainloop()