Esempio n. 1
0
    def __init__(self, usr_file):
        self.data = Data()

        self.file = usr_file
        self.person = ''
        self.msg_mail = self.data.read_template(self.person, self.file)

        self.adress_to = ''
        self.subject = ''

        self.ed_msg_mail = ''
Esempio n. 2
0
class Watchdir:

	data = Data()

	patterns = "*"
	ignore_patterns = ""
	ignore_directories = False
	case_sensitive = True
	event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)

	event_handler.on_created = on_created
	event_handler.on_deleted = on_deleted
	event_handler.on_modified = on_modified
	event_handler.on_moved = on_moved

	path = data.dir
	go_recursively = True
	observer = Observer()
	observer.schedule(event_handler, path, recursive=go_recursively)

	def run_watch(self):
		self.observer.start()
		try:
			while True:
				time.sleep(1)
		except KeyboardInterrupt:
			self.observer.stop()
			self.observer.join()
Esempio n. 3
0
    def send_mail(self, adress_to, subject, message, file):
        data = Data()

        filename = os.path.basename(file)

        msg_mail = MIMEMultipart()
        msg_mail["From"] = data.adress_from
        msg_mail["To"] = adress_to
        msg_mail["Subject"] = subject

        msg_mail.attach(MIMEText(message, 'plain'))

        with open(file, "rb") as attachment:
            part = MIMEBase("application", "octet-stream")
            part.set_payload(attachment.read())

        encoders.encode_base64(part)

        part.add_header("Content-Disposition",
                        f"attachment; filename= {filename}")

        msg_mail.attach(part)
        text = msg_mail.as_string()

        context = ssl.create_default_context()
        with smtplib.SMTP_SSL(data.host, data.port, context=context) as server:
            server.login(data.adress_from, data.password)
            server.sendmail(data.adress_from, adress_to, text)
Esempio n. 4
0
def ask_usr(file):
	# ask user to send
	base_file = os.path.basename(file)

	data = Data()
	win = Window(base_file)
	mail = Send()

	win.popup()
	if win.ed_msg_mail and win.adress_to and win.subject:
		mail.send_mail(win.adress_to, win.subject, win.ed_msg_mail, file)
	
	destination = data.sent_dir + base_file
	os.rename(file, destination)
Esempio n. 5
0
def main():
    malopolska = Data('terc.csv').create_data()
    menu = Menu()
    while True:
        os.system('clear')
        print(menu.options())
        option = input('\nChose the option:')
        if option == '1':
            menu.print_statistics()
        elif option == '2':
            menu.print_longest_names()
        elif option == '3':
            menu.print_largest_county()
        elif option == '4':
            menu.print_multicategory_names()
        elif option == '5':
            menu.advanced_search()
        elif option == '0':
            sys.exit()
Esempio n. 6
0
def start():
    print("Loading the files and preparing the system...")

    files_list = get_file_list(
        "technology_texts/python-3.8.4-docs-text/python-3.8.4-docs-text/c-api")
    # files_list = get_file_list("technology_texts/python-3.8.4-docs-text/python-3.8.4-docs-text/whatsnew")
    complete = Complete(Data(files_list))

    # complete = Complete(Data(["technology_texts/python-3.8.4-docs-text/python-3.8.4-docs-text/about.txt"]))

    print("The system is ready.")

    input_ = ' '.join((''.join(i for i in input("\n\nEnter your text: ")
                               if i in string.ascii_letters + ' ')).split())

    while (1):
        text = " "

        while text[-1] != '#':
            match_sentences = complete.get_best_k_completions(input_)

            if len(match_sentences) != 0:
                for sentence in match_sentences:
                    print(
                        f"{sentence.completed_sentence} ({files_list[sentence.source_text]} {sentence.offset})"
                    )
            else:
                print("there is no items")

            # print(input_, end="")
            text = input(input_)
            input_ += ' '.join(
                (''.join(i for i in text
                         if i in string.ascii_letters + ' ')).split())

        input_ = ' '.join(
            (''.join(i for i in input("\n\nEnter your text: ")
                     if i in string.ascii_letters + ' ')).split())
Esempio n. 7
0
def main():
    #myfuncs = ['constant', 'upstream_downstream', 'polynomial1',  'ackbar', 'eclipse', 'sine2']
    myfuncs = [
        'constant', 'upstream_downstream', 'polynomial1', 'ackbar', 'eclipse',
        'gp_sho'
    ]
    #myfuncs = ['constant', 'upstream_downstream', 'polynomial1',  'ackbar',  'gp_sho']
    #myfuncs = ['constant', 'upstream_downstream', 'polynomial1',  'model_ramp', 'eclipse', 'gp_sho']

    #significance above which to mask outliers
    #outlier_cut = 10.

    #parses command line input
    try:        opts, args = \
           getopt.getopt(sys.argv[1:],
               "hov", ["help", "show-plot", "run-mcmc", "plot-raw-data",
               "plot-sys", "path=", "fit-white=", "divide-white"]
           )
    except getopt.GetoptError:
        usage()

    #defaults for command line flags
    verbose = False
    output = False
    show_plot = False
    run_mcmc = False
    run_lsq = True
    plot_raw_data = False
    path = "spec_lc"
    fit_white = False
    divide_white = False

    for o, a in opts:
        if o in ("-h", "--help"): usage()
        elif o == "-o": output = True
        elif o == "-v": verbose = True
        elif o == "--show-plot": show_plot = True
        elif o == "--run-mcmc": run_mcmc, run_lsq = True, False
        elif o == "--run-lsq": run_lsq = True
        elif o == "--plot-raw-data": plot_raw_data = True
        elif o == "--path": path = a
        elif o == "--fit-white": fit_white, white_file = True, a
        elif o == "--divide-white": divide_white = True
        else: assert False, "unhandled option"

    flags = {
        'verbose': verbose,
        'show-plot': show_plot,
        'plot-raw-data': plot_raw_data,
        'output': output,
        'out-name': 'none.txt',
        'run-lsq': run_lsq,
        'run-mcmc': run_mcmc,
        'divide-white': divide_white,
        'fit-white': fit_white
    }

    #reads in observation and fit parameters
    obs_par = {
        x['parameter']: x['value']
        for x in ascii.read("config/obs_par.txt", Reader=ascii.CommentedHeader)
    }
    fit_par = ascii.read("config/fit_par.txt", Reader=ascii.CommentedHeader)

    files = glob.glob(os.path.join(path, "*"))
    if fit_white: files = glob.glob(white_file)

    flags['out-name'] = "fit_" + pythontime.strftime("%Y_%m_%d_%H:%M") + ".txt"

    for f in files:
        data = Data(f, obs_par, fit_par)
        model = Model(data, myfuncs)
        data, model, params = lsq_fit(fit_par, data, flags, model, myfuncs)
        """data.err *= np.sqrt(model.chi2red)                                      
        data, model, params = lsq_fit(fit_par, data, flags, model, myfuncs)  
        if flags['verbose'] == True: print "rms, chi2red = ", model.rms, model.chi2red"""

        #FIXME : make this automatic!
        """outfile = open("white_systematics.txt", "w")
        for i in range(len(model.all_sys)): print>>outfile, model.all_sys[i]
        outfile.close()"""

        if flags['run-mcmc']:
            output = mcmc_fit(data, model, params, f, obs_par, fit_par)
Esempio n. 8
0
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(
    labels=y,
    logits=logits
))
acc = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(logits, 1), tf.argmax(y, 1)), tf.float16))
# 优化
train_step = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss)

from read_data import Data

epoches = 100
batch_size = 32
max_train_batches = 33886 // batch_size
test_batch_size = 32
max_test_batches = 2000 // test_batch_size
data = Data('data.npz')

with tf.Session() as sess:
    all_var = tf.global_variables()
    sess.run(tf.global_variables_initializer())
    saver = tf.train.Saver()
    # saver.restore(sess, 'model_saved/emotion')
    # print('读取模型成功')

    for i in range(epoches):
        start = time.time()
        # 训练loss
        total_loss = 0
        for j in range(max_train_batches):
            x_this_batch, y_this_batch = data.get_random_train_batch(batch_size)
            train_step.run(feed_dict={
from utils.functions import lr_decay, batchify_sequence_labeling_with_label, predict_check, evaluate
import torch
import logging
import sys
import numpy as np
import datetime

logger = logging.getLogger(__name__)
logger.setLevel(level=logging.INFO)
handler = logging.FileHandler('log/%s_log.txt' %
                              sys.argv[0].split('/')[-1].replace('.py', ''))
logger.addHandler(handler)

config = CnnLstmAttnCrfConfig()
# 读取样本
data = Data()

seed_num = 42
random.seed(seed_num)
torch.manual_seed(seed_num)
np.random.seed(seed_num)


def train():
    total_batch = 0
    # model = CnnLstmCrf(config)
    model = CnnLstmAttnCrf(data)
    optimizer = optim.SGD(model.parameters(),
                          lr=config.lr,
                          momentum=config.momentum,
                          weight_decay=config.l2)
Esempio n. 10
0
class Window:
    def __init__(self, usr_file):
        self.data = Data()

        self.file = usr_file
        self.person = ''
        self.msg_mail = self.data.read_template(self.person, self.file)

        self.adress_to = ''
        self.subject = ''

        self.ed_msg_mail = ''

    def popup(self):

        # root
        root = Tk()
        root.title("Sending Message")
        root.resizable(False, False)

        def exit_gui(send):
            if send:
                self.adress_to = to.get()
                self.subject = subject.get()
                self.ed_msg_mail = mail.get(1.0, "end-1c")
                root.destroy()
            else:
                self.ed_msg_mail = False
                self.subject = False
                self.adress_to = False
                root.destroy()

        def enter_person(keystroke):
            self.person = to.get()
            msg.set(f"Sending email with {self.file} to {self.person}\n")
            root.update_idletasks

            self.msg_mail = self.data.read_template(self.person, self.file)
            mail.delete(1.0, END)
            mail.insert(INSERT, self.msg_mail)

            self.adress_to = self.data.read_adress_to(self.person)
            to.delete(0, END)
            to.insert(INSERT, self.adress_to)

        # heading
        msg = StringVar()
        msg.set(f"Sending email with {self.file} to _____\n")

        message = Label(root, textvariable=msg, font='none 13 bold')
        message.grid(row=0, column=0, columnspan=4, pady=10, padx=10)

        # from
        from_label = Label(root, text="From:")
        from_label.grid(row=1, column=0, columnspan=1)

        from_adress = Entry(root, width=40)
        from_adress.grid(row=1, column=1, columnspan=3, pady=10, padx=20)
        from_adress.insert(INSERT, self.data.adress_from)

        # to
        to_label = Label(root, text="To:")
        to_label.grid(row=2, column=0, columnspan=1)

        to = Entry(root, width=40)
        to.grid(row=2, column=1, columnspan=3, pady=10, padx=20)
        to.bind('<Return>', enter_person)

        # subject
        subject_label = Label(root, text="Subject:")
        subject_label.grid(row=3, column=0, columnspan=1)

        subject = Entry(root, width=40)
        subject.grid(row=3, column=1, columnspan=3, pady=10, padx=20)
        subject.insert(INSERT, self.file)

        # message
        mail = Text(root, height=20, width=40, pady=10, padx=10)
        mail.grid(row=4, column=0, columnspan=4, pady=10, padx=20)
        mail.insert(INSERT, self.msg_mail)

        mail.focus()
        mail.tag_add(SEL, "1.12", "1.24")
        mail.mark_set(INSERT, "1.12")
        mail.see(INSERT)

        # buttons
        empty1 = Label(root, text='')
        empty1.grid(row=5, column=0)

        button2 = Button(root, text="Cancel", command=lambda: exit_gui(False))
        button2.grid(row=5, column=1, pady=10)

        button1 = Button(root,
                         text="Send",
                         font="none 10 bold",
                         command=lambda: exit_gui(True))
        button1.grid(row=5, column=2, pady=10)

        empty2 = Label(root, text='')
        empty2.grid(row=5, column=3)

        # root
        root.mainloop()
Esempio n. 11
0
File: test.py Progetto: ruiann/RHS
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import time
from RHS import RHS
from read_data import Data

segment_per_sample = 1000
segment_length = 100
channel = 3
test_count = 30

model_dir = './model'

data = Data(segment_per_sample, segment_length)
rhs = RHS(layer=[data.class_num()])


def test():
    data.init_test_data()
    x = tf.placeholder(tf.float32, shape=(test_count, None, channel))
    lstm_code = rhs.rnn(x)
    regression = rhs.regression(lstm_code)
    classification = tf.reduce_mean(tf.nn.softmax(regression), 0)
    index = tf.argmax(classification, dimension=0)
    sample_code = tf.reduce_mean(lstm_code, 0)

    sess = tf.Session()

    with sess.as_default():
import logging
import sys
import numpy as np
from model.seqlabel import SeqLabel

logging.basicConfig(filemode='w')
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.INFO)
handler = logging.FileHandler('log/%s_log.txt' % sys.argv[0].split('/')[-1].replace('.py',''))
logger.addHandler(handler)

config = CnnLstmConfig()
map_location = 'cpu' if config.device.type == 'cpu' else None
gpu = False if config.device.type == 'cpu' else True
# 读取样本
data = Data()
data.gpu = gpu
data.char_alphabet_size = len(data.char_alphabet) + 1
data.word_alphabet_size = len(data.word_alphabet) + 1
data.label_alphabet_size = len(data.label_alphabet) + 1
data.feat_alphabet_size = len(data.feat_alphabet) + 1

data.dropout = 0.5
data.word_emb_dim = 300
data.char_emb_dim = 300
data.feature_num = 1
data.hidden_dim = 200
data.char_hidden_dim = 50
data.feature_emb_dim = 5
data.pretrain_char_embedding = None
Esempio n. 13
0
def main():
    data = Data(settings.CONFIG['IMPORT_URL'])
    data.read()
Esempio n. 14
0
#Analysis configurations
analysis_thresholds = [1,5,10]

#Definition of parameters
separator = "#"
season_sep = "TEMP_INI\n"
in_period = 1990
fi_period = 2015
seasons_evaluated = list(range(in_period,fi_period+1,1))

#Data paths
ref_path = os.getcwd()+r"\..\data\hist_"+str(in_period)+"_"+str(fi_period)+".txt"
images_path = os.getcwd()+r"\..\results\images\\"
pajek_path = os.getcwd()+r"\..\results\networks\\"

data = Data(separator=separator,ini=in_period,fin=fi_period,path=ref_path)
conf_name = "_conf_"
if deploy_know_how_relations:
    conf_name += "KH_"
if deploy_rivality_relations:
    conf_name += "RIV_"


#Loading Data
data_content = data.read_dataset(season_sep=season_sep)
data_model = History()
data_model.build(seasons_content=data_content,seasons_ids=seasons_evaluated)

#Building the model
temporal_network = {}
temporal_network_kh = {}
Esempio n. 15
0
File: encode.py Progetto: ruiann/RHS
import tensorflow as tf
import time
import random
from RHS import RHS
from read_data import Data

segment_per_sample = 1000
segment_length = 100
channel = 3
test_count = 30
test_period = 30

log_dir = './log'
model_dir = './model'

data = Data(segment_per_sample, segment_length)
rhs = RHS(lstm_size=800, class_num=data.class_num())


def test():
    data.init_test_data()
    x = tf.placeholder(tf.float32, shape=(test_count, None, channel))
    lstm_code = tf.reduce_sum(rhs.lstm(x, test_count), 0)

    sess = tf.Session()

    with sess.as_default():
        sess.run(tf.global_variables_initializer())

        saver = tf.train.Saver()
        checkpoint = tf.train.get_checkpoint_state(model_dir)
Esempio n. 16
0
                    type=bool,
                    default=False,
                    help='Visualize data distribution')
parser.add_argument('--num_epochs',
                    type=int,
                    default=5,
                    help='Number of epochs to train on')
parser.add_argument('--train', default=True, type=bool, help='train the model')

opt = parser.parse_args()

if opt.use_cuda:
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# '''

df = Data()

train_df = df.train_df
valid_df = df.valid_df
train_labels_data = df.train_labels_data
valid_labels_data = df.valid_labels_data

if opt.samples:
    see_samples(train_df)
# plt.show()

train_df['Label'] = train_df.apply(lambda x: 1
                                   if 'positive' in x.FilePath else 0,
                                   axis=1)
train_df['BodyPart'] = train_df.apply(lambda x: x.FilePath.split('/')[2][3:],
                                      axis=1)