Beispiel #1
0
                    #grabs the player's discord id
                    player_name = player_data[target_member.id][0]

                    #sends the id to the champion function, which will return the champion name
                    champ_name = Get_Champion(player_name)

                    #sets the nickname
                    await target_member.edit(nick=champ_name)

                    player_data[target_member.id][2] = int(time.time())
                    print('timer passed')

                    run_timer_thread(target_member)

                #'handles' the error
                except KeyError:
                    pass
                    print('timer exceded')

    #now that the rest of the code is out of the way, it's time to start the bot
    client.run(token)

#handles anything that might interrupt the code
#it will back up player_data to its storage file before closing
except:

    data = open('data.py', 'w')
    data.truncate()
    data.write("player_data={}".format(player_data))
    data.close()
Beispiel #2
0
    def __del__(self):
        """
		Tanca la comunicació.
		"""
        data.close()
Beispiel #3
0
def event(user_id, event_name):
    sql = "INSERT INTO events (user_id, timestamp, event_value_id) VALUES (%s, %s, %s)"
    cursor = get_cursor()
    cursor.execute(sql, (user_id, time.time(), event_value_ids[event_name]))
    commit()
    close()
Beispiel #4
0
    def fit_ESR(self, name, datapath = '', fit_data = True, save = True, f_dip = 2.828E9):

        if datapath == '':
            datapath = os.path.join(r'D:\measuring\data', 
                    self.get_latest_data(name))
        else:
            datapath = datapath
        
        ###########################################
        ######## MEASUREMENT SPECS ################
        ###########################################
        files = os.listdir(datapath)
        
        for k in files:
            if (name in k) and ('.npz' in k):
                data_file = k
        
        data = np.load(os.path.join(datapath,data_file))
        
        mw_freq = data['freq']
        counts = data['counts']
        data.close()

        f_dip_guess = f_dip
        offset_guess = counts.max()
        dip_depth_guess = offset_guess - counts.min()
        width_guess = 5e-3

        if fit_data:
            
            fit_result=fit.fit1d(mw_freq/1E9, counts, common.fit_gauss, 
                offset_guess, dip_depth_guess, f_dip_guess/1E9,width_guess,
                do_plot = False, do_print = False, newfig = False,ret=True)
            
            x0 = fit_result['params_dict']['x0']
            a = fit_result['params_dict']['a']
            A = fit_result['params_dict']['A']
            sigma = fit_result['params_dict']['sigma']
            #s0 = fit_result[0]['params_dict']['s0']

            x = np.linspace(mw_freq.min(), mw_freq.max(), 501)
            fit_curve = np.zeros(len(x))
            
            fit_curve = np.exp(-(((x/1E9)-x0)/sigma)**2)
            fit_curve = a*np.ones(len(x)) + A*fit_curve

        plot1 = qt.Plot2D(mw_freq/1E9, counts, '-ok', x/1E9, fit_curve, '-r',name='ESR',clear=True) 
        plot1.set_xlabel('MW frequency (GHz)')
        plot1.set_ylabel('Integrated counts')
        plot1.set_plottitle('MW frequency sweep')
        if save:
            plot1.save_png(datapath+'\\histogram_integrated.png')

        data.close()
        #plot1.clear()
        #plot1.quit()

        if save:
            #Save a dat file for use in e.g. Origin with the dark esr data.
            curr_date = '#'+time.ctime()+'\n'
            col_names = '#Col0: MW freq (GHz)\tCol1: Integrated counts\n'
            col_vals = str()
            for k in range(len(counts)):
                col_vals += self.num2str(mw_freq[k]/1E9,10)+'\t'+self.num2str(counts[k],0)+'\n'
            fo = open(datapath+'\\mw_f_calibration_integrated_histogram.dat', "w")
            for item in [curr_date, col_names, col_vals]:
                fo.writelines(item)
            fo.close()

        return x0*1E9