Esempio n. 1
0
def animate(ii):
    most_recent = Reader.get_timeset(table="Sensor Plot", num=1)
    Reader.close()
    for i, key in enumerate(param_dict, 1):
        current_plot = param_dict[key]
        data_stream = current_plot.incoming_data
        data_stream.pop()
        data_stream.insert(1, most_recent[0][i])
        current_plot.incoming_data = data_stream
        current_plot.make_plot(param=key)
Esempio n. 2
0
 def __init__(self, system, gold=None, fmt=DEFAULT_FMT):
     """
     system - system output
     gold - gold standard
     fmt - format
     """
     self.system = sorted(Reader(open(system)))
     self.gold = sorted(Reader(open(gold)))
     fmt_func = FMTS.get(fmt)
     assert fmt_func is not None
     self.fmt_func = fmt_func
Esempio n. 3
0
def signup():
    previousCredentials=Reader.read_file('./data/credentials.txt')
    if request.method=="GET":
        return render_template('signup.html', title='Sign up')
    elif request.method=="POST":
        new_user=request.form['nuser']
        new_pswd=request.form['npswd']
        new_credentials='%s,%s'%(new_user,new_pswd)
        if new_user=='' or new_pswd=='' or new_user in previousCredentials or new_user.find(',')!=-1 or new_pswd.find(',')!=-1:
            return render_template('form.html', error='Invalid signup credentials', title='Login')
        else:
            Reader.write_file('./data/credentials.txt',new_credentials+'\n','a')
            return render_template('form.html', error='Successfully signed up!', title='Login')
    else:
        return 'yo'
Esempio n. 4
0
def test_data():
    d = list(Reader(open(DATA)))
    assert len(d) == 1
    doc = list(d)[0]
    assert len(list(doc.iter_mentions())) == 2
    assert len(list(doc.iter_links())) == 1
    assert len(list(doc.iter_nils())) == 1
Esempio n. 5
0
 def load(self):
     """
     载入相关statistics数据
     """ 
     dataPath = self.getDataPath(date = self.date)
     self.data = Reader.read(dataPath)
     if not self.data:
             raise IOError
     return self.data  
Esempio n. 6
0
def validate(u,p):
    request_data=request.form
    credentials=Reader.getCsvDict('./data/credentials.txt')
    if request_data['user'] in credentials and request_data['user']!='':
        if request_data['pswd']==credentials[request_data['user']][0]:
            return True
        else:
            return False
    else:
        return False
Esempio n. 7
0
def validate(u, p):
    request_data = request.form
    credentials = Reader.getCsvDict('./data/credentials.txt')
    if request_data['user'] in credentials and request_data['user'] != '':
        if request_data['pswd'] == credentials[request_data['user']][0]:
            return True
        else:
            return False
    else:
        return False
Esempio n. 8
0
 def load(self,date=None):
     if not self.data.get(date,None):
         strategicPath = os.path.join(self.conf.get("SYS_HOME",""),self.conf.get("STRATEGIC_DATA_PATH",STRATEGIC_DATA_PATH),date+SUFFIX)
         strategic = Reader.read(strategicPath)
         if strategic:
             self.data[date] = strategic 
         else:
             logging.warning("Load strategic data failed.Date is %s ,path is %s" % (date,strategicPath))
             self.data[date] = []
             sys.exit(2)
     return self.data.get(date,[])
Esempio n. 9
0
def signup():
    previousCredentials = Reader.read_file('./data/credentials.txt')
    if request.method == "GET":
        return render_template('signup.html', title='Sign up')
    elif request.method == "POST":
        new_user = request.form['nuser']
        new_pswd = request.form['npswd']
        new_credentials = '%s,%s' % (new_user, new_pswd)
        if new_user == '' or new_pswd == '' or new_user in previousCredentials or new_user.find(
                ',') != -1 or new_pswd.find(',') != -1:
            return render_template('form.html',
                                   error='Invalid signup credentials',
                                   title='Login')
        else:
            Reader.write_file('./data/credentials.txt', new_credentials, 'a')
            return render_template('form.html',
                                   error='Successfully signed up!',
                                   title='Login')
    else:
        return 'yo'
Esempio n. 10
0
    def collect(self,strategic = None ,statisticsProjectPath = None):
        """
        对于整体数据,缓存之前计算。对于指定策略,暂时只收集15日内数据,反映短期内变动情况。
        收集统计数据
        >> statistics.stock == testCase['stock']
        >> statistics.collect()
        
        收集指定策略统计数据
        >> statistics.stock == testCase['stock']
        >> statistics.collect(strategic = testCase['collectStrategic']) 

        @param {list} strategic  符合策略的code list
        """
        conf={}
        conf.update(self.conf)
        isCache = False
        data={}
        if strategic: #计算指定策略统计
            allCode = strategic #符合指定策略的 code 可通过strategic[date][strategicName]读出
            allDate = []
            for i in range(0,conf.get("MIN_DATA_NUM",MIN_DATA_NUM)):
                date=Date.getDate(0-i,conf.get('date',Date.getDate()))
                allDate.append(date)
        else:    #计算整体统计
            isCache = True
            allDate = self.stock.allDate
            allCode = self.stock.allCode

        if isCache: #读取之前统计缓存
            data = Reader.read(path = self.getDataPath(dataType = "cache"))
            for date in allDate:
                if date in data and date in allDate:
                    allDate.remove(date)
            
        conf.update({
            "date":self.date,
            "stock":self.stock,
            "allCode":allCode
        })

        expression=Expression(conf)
        statisticsProjectPath = statisticsProjectPath or os.path.join(conf.get("SYS_HOME"),conf.get("STATISTICS_PROJECT_PATH"))
        expressions = expression.load(path = statisticsProjectPath)
        for date in allDate:
            result={} #初始化result变量,让result能在公式里直接使用,并且result[name]也能使用
            for code in allCode:
                result[code]={}
            expression.execute(expression= conf.get("expressions",expressions), context = {"result":result,"date":date})
            if not result:
                break;
            data[date]=result
        if isCache:
            Dumper.dump(path = self.getDataPath(dataType = "cache"),data =data)
        return data
Esempio n. 11
0
    def __call__(self):
        all_counts = defaultdict(dict)
        gold = sorted(Reader(open(self.gold)))
        for path in self.systems:
            system = sorted(Reader(open(path)))
            for match, per_doc, overall in Evaluate.count_all(system, gold):
                all_counts[match][path] = (per_doc, overall)

        results = [
            {
                'sys1': sys1,
                'sys2': sys2,
                'match': match,
                'stats': self.significance(match_counts[sys1],
                                           match_counts[sys2])
            } for sys1, sys2 in itertools.combinations(self.systems, 2)
            for match, match_counts in sorted(
                all_counts.iteritems(), key=lambda (k, v): MATCHES.index(k))
        ]

        return self.fmt(results, self.metrics)
Esempio n. 12
0
def log_in():
    if request.method=="GET":
        return render_template('form.html', title='login')                        
    elif request.method=="POST":#Verifies the username and password against constants at the top
        request_data=request.form#Takes the immutable dictionary of the user's inputs and saves it in a variable
        credentials=Reader.getCsvDict('./data/credentials.txt')
        if validate(request_data['user'],request_data['pswd']):
            return render_template('form.html', title='login', error='Successful login')
        else:
            return render_template('form.html', error='Invalid username or password', title='Login')
    else:
        return 'yo'
Esempio n. 13
0
def signup():
    previousCredentials = Reader.read_file("./data/credentials.txt")
    if request.method == "GET":
        return render_template("signup.html", title="Sign up")
    elif request.method == "POST":
        new_user = request.form["nuser"]
        new_pswd = request.form["npswd"]
        new_credentials = "%s,%s" % (new_user, new_pswd)
        if (
            new_user == ""
            or new_pswd == ""
            or new_user in previousCredentials
            or new_user.find(",") != -1
            or new_pswd.find(",") != -1
        ):
            return render_template("form.html", error="Invalid signup credentials", title="Login")
        else:
            Reader.write_file("./data/credentials.txt", new_credentials, "a")
            return render_template("form.html", error="Successfully signed up!", title="Login")
    else:
        return "yo"
Esempio n. 14
0
    def initialize_system(self):
        if not self.initialized:
            # Read data directly from this class
            reader = Reader()
            reader.write_serialized()

            users, movies, self.ratingsTuples = reader.load_serialized()
            (self.ratingsMatrix, self.userIndexes, self.moviesIndexes) = reader.create_ratings_matrix(users, movies)

            # Store data in class attributes
            self.users = users
            self.movies = movies

            # Initialize both matrix from SVD
            numUsers = len(users)
            numMovies = len(movies)

            ## Users preferences: numUsers * numLatentFactors
            self.usersPreferences = np.full(
                shape=(numUsers, self.numLatentFactors),
                fill_value=self.initializationValue,
                dtype=float)

            ## Movies description: numMovies * numLatentFactors
            self.moviesPreferences = np.full(
                shape=(numMovies, self.numLatentFactors),
                fill_value=self.initializationValue,
                dtype=float
            )

            # Control initialization of the system
            self.initialized = True
Esempio n. 15
0
        def GetValues():
            with open(config_path, "r") as file:
                config_settings = list(csv.reader(file))
            most_recent = Reader.get_timeset(table="Sensor Plot", num=1)
            Reader.close()

            for i, key in enumerate(param_dict):
                current_param_val = most_recent[0][i]
                live_text = live_text_label[i]
                current_plot = param_dict[key]
                if current_param_val > float(
                        config_settings[3][i]) or current_param_val < float(
                            config_settings[4][i]):
                    live_text.config(text=most_recent[i], fg="red", bg="white")
                    current_plot.plot_color = 'r'
                else:
                    live_text.config(text=most_recent[i],
                                     fg="black",
                                     bg="white")
                    current_plot.plot_color = 'g'

            self.after(5000, GetValues)
Esempio n. 16
0
def test_sentences():
    """ Checks that we can read contiguous sentences with the indices making sense. """
    docs = list(Reader(open(DATA_FULL)))
    for d in docs:
        last = None
        for s in d.sentences:
            for span in s:
                if last:
                    assert span.start == last
                else:
                    assert span.start == 0
                last = span.end
                if isinstance(span, Mention) and span.link is not None:
                    assert isinstance(span.score, float)
Esempio n. 17
0
def log_in():
    if request.method == "GET":
        return render_template("form.html", title="login")
    elif request.method == "POST":  # Verifies the username and password against constants at the top
        request_data = request.form  # Takes the immutable dictionary of the user's inputs and saves it in a variable
        credentials = Reader.getCsvDict("./data/credentials.txt")
        if request_data["user"] in credentials and request_data["user"] != "":
            if request_data["pswd"] == credentials[request_data["user"]][0]:
                return "success"
            else:
                return render_template("form.html", error="Invalid username or password", title="Login")
        else:
            return render_template("form.html", error="Invalid username or password", title="Login")
    else:
        return "yo"
Esempio n. 18
0
def log_in():
    if request.method == "GET":
        return render_template('form.html', title='login')
    elif request.method == "POST":  #Verifies the username and password against constants at the top
        request_data = request.form  #Takes the immutable dictionary of the user's inputs and saves it in a variable
        credentials = Reader.getCsvDict('./data/credentials.txt')
        if validate(request_data['user'], request_data['pswd']):
            return render_template('form.html',
                                   title='login',
                                   error='Successful login')
        else:
            return render_template('form.html',
                                   error='Invalid username or password',
                                   title='Login')
    else:
        return 'yo'
Esempio n. 19
0
    def __init__(self):
        self.G = generator_resnet('G')
        self.F = generator_resnet('F')
        self.Dx = discriminator('Dx')
        self.Dy = discriminator('Dy')

        # train graph
        self.fake_pool_x = image_pool(50)
        self.fake_pool_y = image_pool(50)
        self.reader_x = Reader(FLAGS.ds_x)
        self.reader_y = Reader(FLAGS.ds_y)

        self.real_x = self.reader_x.feed()
        self.fake_y = self.G(self.real_x, False)
        self.cyc_x = self.F(self.fake_y, False)

        self.real_y = self.reader_y.feed()
        self.fake_x = self.F(self.real_y)
        self.cyc_y = self.G(self.fake_x)

        self.pool_x = tf.placeholder(tf.float32, [None, 256, 256, 3],
                                     name='Dx_pool')
        self.pool_y = tf.placeholder(tf.float32, [None, 256, 256, 3],
                                     name='Dy_pool')

        self.dy_fake = self.Dy(self.fake_y, False)
        self.dy_real = self.Dy(self.real_y)
        self.dx_fake = self.Dx(self.fake_x, False)
        self.dx_real = self.Dx(self.real_x)

        self.iden_x = self.G(self.real_y)
        self.iden_y = self.F(self.real_x)

        # loss def
        self.Ix_loss = tf.reduce_mean(tf.abs(self.iden_x - self.real_y))
        self.Iy_loss = tf.reduce_mean(tf.abs(self.iden_y - self.real_x))
        self.I_loss = (self.Ix_loss +
                       self.Iy_loss) * FLAGS.lamda * FLAGS.lamda_id

        self.C_loss = cyc_loss(self.real_x, self.cyc_x, self.real_y,
                               self.cyc_y) * FLAGS.lamda
        self.G_loss = gen_loss(self.dy_fake)
        self.F_loss = gen_loss(self.dx_fake)

        self.loss_G = self.G_loss + self.F_loss + self.C_loss + self.I_loss

        self.Dx_loss = dis_loss(self.dx_real, self.Dx(self.pool_x))
        self.Dy_loss = dis_loss(self.dy_real, self.Dy(self.pool_y))

        self.loss_D = self.Dx_loss + self.Dy_loss

        # optim
        self.lr = tf.where(
            tf.greater(global_step, FLAGS.start_decay),
            tf.train.polynomial_decay(FLAGS.init_lr,
                                      global_step - FLAGS.start_decay,
                                      FLAGS.decay_step, 0), FLAGS.init_lr)
        optimizer = tf.train.AdamOptimizer(self.lr, beta1=0.5)
        self.g_optim = optimizer.minimize(self.loss_G,
                                          var_list=self.G.vars + self.F.vars)
        self.d_optim = optimizer.minimize(self.loss_D,
                                          var_list=self.Dx.vars + self.Dy.vars)

        self.inc_step = tf.assign_add(global_step, 1)
        self.fit_summ = tf.summary.merge([
            tf.summary.scalar('lr', self.lr),
            tf.summary.scalar('G_loss', self.G_loss),
            tf.summary.scalar('F_loss', self.F_loss),
            tf.summary.scalar('Dx_loss', self.Dx_loss),
            tf.summary.scalar('Dy_loss', self.Dy_loss),
            tf.summary.scalar('Ix_loss', self.Ix_loss),
            tf.summary.scalar('Iy_loss', self.Iy_loss),
            tf.summary.histogram('dx_fake', self.dx_fake),
            tf.summary.histogram('dx_real', self.dx_real),
            tf.summary.histogram('dy_fake', self.dy_fake),
            tf.summary.histogram('dy_real', self.dx_real)
        ])

        # test graph
        # forward
        self.reader_x_t = Reader(FLAGS.ds_x + '_t')
        self.test_x = self.reader_x_t.feed(6)
        self.test_fake_y = self.G(self.test_x)
        self.test_cyc_x = self.F(self.test_fake_y)

        # backward
        self.reader_y_t = Reader(FLAGS.ds_y + '_t')
        self.test_y = self.reader_y_t.feed(6)
        self.test_fake_x = self.F(self.test_y)
        self.test_cyc_y = self.G(self.test_fake_x)
Esempio n. 20
0
            ax.xaxis_date()
            ax.xaxis.set_major_formatter(mdates.DateFormatter('%I:%M:%S %p'))
            [tk.set_visible(True) for tk in ax.get_xticklabels()]
            [label.set_rotation(10) for label in ax.xaxis.get_ticklabels()
             ]  #slant the x axis tick labels for extra coolness
            ax.set_xlim(incoming_data[-1], incoming_data[0])
            ax.xaxis.set_major_locator(mticker.MaxNLocator(nbins=4))
        plot.fill_between(tList,
                          incoming_data,
                          facecolor=plot_color,
                          edgecolor=plot_color,
                          alpha=0.5)  #blue @initilization


for i, param in enumerate(param_list, 1):  #tk.Label self refers to Homepage
    most_recent = Reader.get_timeset(table="Sensor Plot", num=20)
    Reader.close()
    for j in enumerate(most_recent):
        tList = most_recent[j][0]
        most_recent_20 = most_recent[j][i]

    param_dict[param] = Sensor_Plot(f.add_subplot(6, 2, i), most_recent_20,
                                    'b')

for i, key in enumerate(param_dict, 1):
    current_plot = param_dict[key]
    current_plot.make_plot(param=key)


###ANIMATE FUNCTION, REMOVE LAST ITEM FROM MOST_RECENT_2O LIST AND INSERT FRESHLY CALLED VALUE TO INDEX[1]
def animate(ii):
Esempio n. 21
0
 def load(self,date):
     if not self.data.get(date,None):
         reporterPath = os.path.join(self.conf.get("SYS_HOME",""),self.conf.get("REPORTER_DATA_PATH",REPORTER_DATA_PATH),date+SUFFIX)
         self.data[date] = Reader.read(reporterPath)
     return self.data.get(date,None)  
Esempio n. 22
0
    while True:
        tic = time.time()
        batch_x, batch_y1_truth, batch_y2_truth = reader.next_batch()
        fd = {
            x_ph: batch_x,
            y1_truth_ph: batch_y1_truth,
            y2_truth_ph: batch_y2_truth,
            lrate_ph: lrate
        }

        batch_loss, batch_summary, _ = sess.run([loss, summary, train], fd)

        step = tf.train.global_step(sess, step_tensor)
        writer.add_summary(batch_summary, step)

        if step % save_every == 0:
            saver.save(sess, os.path.join(log_dir, '%d.ckpt' % step))

        toc = time.time()
        print('%s: step %d, loss %e, interval %f' %
              (name, step, batch_loss, toc - tic))


if __name__ == '__main__':
    reader = Reader(
        './data/train.txt',
        './data/wav',
        1,
    )
    train_baseline(reader, 'baseline', './log', 0.0001)
Esempio n. 23
0
def sendEmail(user_settings):
    while True:
        #if not sunday - return
        weekday = datetime.today().weekday()
        time = datetime.now()
        hour = time.hour
        minute = time.minute
        second = time.second

        if weekday == 6 and hour == 12 and minute == 0 and second == 0:
            pass
        else:
            continue

        config_path, db_path, _ = user_settings()
        with open(config_path, 'r') as file:
            config_settings = list(csv.reader(file))
            strTos = config_settings[3]
            strTos = list(filter(('Email').__ne__, strTos))

        # Define these once; use them twice!
        strFrom = '*****@*****.**'

        ###########

        #we need to edit this so that it takes from GUI
        #we will DEFINITELY have to 'import GUI'

        ###########
        sec_per_week = 7 * 24 * 60 * 60
        tsamp = 1
        nsamp = 10
        current_time = int(datetime.now().timestamp())
        information = Reader(db_path, 'sensor_db.db').query_by_time(
            current_time - 604800, current_time, '*')

        #information = Reader(db_path,'sensor_db.db').query_by_num(table="SensorData", num=60480) #num is the number of data points. We need to figure out what num is for a whole week
        #information = Reader(db_path,'sensor_db.db').query_by_num(table="SensorData", num= sec_per_week / (tsamp * nsamp)) #num is the number of data points. We need to figure out what num is for a whole week
        #Daniel will apply SQL lite later

        def funcTime(x):
            return x[0]

        timeInfo = list(map(funcTime, information))
        timeInfo = mdates.epoch2num(timeInfo)

        def func1(x):
            return x[1:]

        information = list(map(func1, information))
        #print('information')
        #print(information)

        param_list = [
            'pH', 'TDS (ppm)', 'Rela. Humidity (%)',
            'Air Temp (\N{DEGREE SIGN}C)', 'Water Temp (\N{DEGREE SIGN}C)',
            'Water Level (cm)'
        ]
        plt.figure(figsize=(11, 8))
        plt.suptitle('Weekly Graphs', fontsize=20, color='#4e2a84')
        #allOfData = {}
        for i in range(len(param_list)):

            def func2(x):
                return x[i]

            partOfInfo = list(map(func2, information))
            #print('part of info')
            #print(partOfInfo)
            #allOfData[param_list[i]] = partOfInfo
            plt.subplot(3, 2, 1 + i)
            plt.plot(timeInfo, partOfInfo, color='#4e2a84')
            plt.title(param_list[i])
            ax = plt.gca()
            ax.axes.xaxis_date()
            ax.axes.xaxis.set_major_formatter(mdates.DateFormatter('%a'))

        title = 'thisweek.png'
        table = 'table.png'

        plt.tight_layout()
        plt.savefig(title)

        avgs = []
        mins = []
        maxs = []
        rounding = [2, 2, 1, 1, 2, 2]
        for i in range(len(param_list)):

            def func2(x):
                return x[i]

            partOfInfo = list(map(func2, information))
            partOfInfo = [x for x in partOfInfo if x]
            avgs.append(round(sum(partOfInfo) / len(partOfInfo), rounding[i]))
            mins.append(round(min(partOfInfo), rounding[i]))
            maxs.append(round(max(partOfInfo), rounding[i]))

        for strTo in strTos:
            # Create the root message and fill in the from, to, and subject headers
            msgRoot = MIMEMultipart('related')
            msgRoot['Subject'] = 'NU-ESW Aquaponics Weekly Update'
            msgRoot['From'] = strFrom
            msgRoot['To'] = strTo
            msgRoot.preamble = 'This is a multi-part message in MIME format.'

            # Encapsulate the plain and HTML versions of the message body in an
            # 'alternative' part, so message agents can decide which they want to display.
            msgAlternative = MIMEMultipart('alternative')
            msgRoot.attach(msgAlternative)

            msgText = MIMEText('This is the alternative plain text message.')
            msgAlternative.attach(msgText)

            tableHtml = '''
                <h2>Weekly Statistics</h2>
                <div class="griddy">
                    <div class="item"><b>Metric</b></div>
                    <div class="item"><b>Average</b></div>
                    <div class="item"><b>Minimum</b></div>
                    <div class="item"><b>Maximum</b></div>
                    <div class="item">pH</div>
                    <div class="item">''' + str(avgs[0]) + '''</div>
                    <div class="item">''' + str(mins[0]) + '''</div>
                    <div class="item">''' + str(maxs[0]) + '''</div>
                    <div class="item">TDS (ppm)</div>
                    <div class="item">''' + str(avgs[1]) + '''</div>
                    <div class="item">''' + str(mins[1]) + '''</div>
                    <div class="item">''' + str(maxs[1]) + '''</div>
                    <div class="item">Humidity (%)</div>
                    <div class="item">''' + str(avgs[2]) + '''</div>
                    <div class="item">''' + str(mins[2]) + '''</div>
                    <div class="item">''' + str(maxs[2]) + '''</div>
                    <div class="item">Air Temp (C)</div>
                    <div class="item">''' + str(avgs[3]) + '''</div>
                    <div class="item">''' + str(mins[3]) + '''</div>
                    <div class="item">''' + str(maxs[3]) + '''</div>
                    <div class="item">Water Temp (C)</div>
                    <div class="item">''' + str(avgs[4]) + '''</div>
                    <div class="item">''' + str(mins[4]) + '''</div>
                    <div class="item">''' + str(maxs[4]) + '''</div>
                    <div class="item">Water Level (cm)</div>
                    <div class="item">''' + str(avgs[5]) + '''</div>
                    <div class="item">''' + str(mins[5]) + '''</div>
                    <div class="item">''' + str(maxs[5]) + '''</div>
                </div>
            '''

            tableCss = '''
                h2 {
                    color: #4e2a84;
                    font-size: 30px;
                    text-align: center;
                }
                .container {
                    height: 250px;
                    width: 100%;
                    margin: 0 auto;
                }
                .griddy {
                    max-width: 60%;
                    margin: 0 auto;
                }
                .item {
                    font-size: 15px;
                    color: black;
                    width: 22%;
                    float: left;
                    border: solid 1px black;
                    padding: 1%;
                }
                .gap {
                    width: 100%;
                    height: 10px;
                }
            '''

            hti = Html2Image(output_path=db_path)
            hti.screenshot(html_str=tableHtml,
                           css_str=tableCss,
                           save_as=table,
                           size=(1100, 350))

            #num needs to be changed accordingly

            # We reference the image in the IMG SRC attribute by the ID we give it below
            #msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>Nifty!', 'html')
            html = '''
                <head>
                    <style>
                        header {
                            top: 0;
                            left: 0;
                            width: 100%;
                            border: solid 1px #CCC;
                            padding: 10px;
                            color: white;
                            background-color: #4e2a84;
                        }
                        h1 {
                            font-size: 40px;
                        }
                        h3 {
                            font-size: 20px;
                        }
                        header * {
                            padding: 0px;
                            margin: 0px;
                        }
                    </style>
                </head>
                <body>
                    <header>
                        <h1>AutoAquaponics</h1>
                        <h3>Weekly Report</h3>
                    </header>
                    <img src="cid:image2">
                    <section class="container"></section>
                    <div class="gap"></div>
                    <img src="cid:image1">
                </body>
                
            '''
            msgText = MIMEText(html, 'html')
            msgAlternative.attach(msgText)

            # This example assumes the image is in the current directory

            fp = open(title, 'rb')
            msgImage = MIMEImage(fp.read())
            fp.close()

            # Define the image's ID as referenced above
            msgImage.add_header('Content-ID', '<image1>')
            msgRoot.attach(msgImage)

            fp = open(table, 'rb')
            tableImage = MIMEImage(fp.read())
            fp.close()
            tableImage.add_header('Content-ID', '<image2>')
            msgRoot.attach(tableImage)

            #otherwise it goes here

            # Send the email (this example assumes SMTP authentication is required)

            email = strFrom
            smtp = 'smtp.gmail.com'
            port = 587
            password = '******'
            server = smtplib.SMTP(smtp, port)

            server.starttls()

            server.login(email, password)
            server.sendmail(email, strTo, msgRoot.as_string())

        os.remove(title)
        os.remove(table)
Esempio n. 24
0
from matplotlib import dates as mdates
#import animation to make graph live
import matplotlib.animation as animation
from matplotlib import style

style.use("seaborn-darkgrid")
#import vertical scroll bar
from vertical_scroll_frame import VerticalScrolledFrame

from main import user_settings

config_path, db_path = user_settings()

#initialize channel_buttons_config, entry configs, and SQLite reader
db_name = 'sensor_testdb.db'
reader = Reader(db_path, db_name)

with open(config_path, "r") as file:
    config_settings = list(csv.reader(file))
    if len(config_settings) != 5:
        with open(config_path, 'w', newline='') as file:
            channel_buttons_config = [-1] * 16
            on_config = [0] * 16
            off_config = [0] * 16
            upper_config = [0] * 11
            lower_config = [0] * 11
            writer = csv.writer(file)
            writer.writerows([
                channel_buttons_config, on_config, off_config, upper_config,
                lower_config
            ])
Esempio n. 25
0
    def fit(self, train_data, target_data, valid_data=None):
        '''
        Fit a seq2seq model on pairs of sequences of source and target
        languages.

        Arguments
        ---------
        train_data: pd.Series of sentences of the source language.
        target_data: pd.Series of sentences of the target language.
        valid_data: tuple of pd.Series input and output sentences.
        '''
        # Construct a tf.Dataset
        dataset = tf.data.Dataset.from_generator(
            lambda: zip(train_data, target_data), (tf.int32, tf.int32),
            output_shapes=(None))
        dataset = dataset.repeat(self.nb_epochs)
        dataset = dataset.shuffle(buffer_size=10000)
        iterator = dataset.make_one_shot_iterator()
        next_element = iterator.get_next()
        # Init
        c_train = np.zeros((self.batch_size, self.hidden_size))
        epoch = 1
        avg_train_loss = 0
        nb_batch = 0
        # Sentence reader
        reader = Reader(batch_size=self.batch_size,
                        nb_sentences=train_data.shape[0],
                        nb_epochs=self.nb_epochs,
                        tf_session=self.session,
                        iterator=next_element)
        while True:
            try:
                x, y, shifted_y = reader.generate_batch()
                fd = {
                    self.input: x,
                    self.gt: y,
                    self.shifted_gt: shifted_y,
                    self.c_t: c_train
                }
                # Run backprop
                _, train_loss = self.session.run(
                    [self.optimizer, self.avg_loss], feed_dict=fd)
                avg_train_loss += train_loss
                nb_batch += 1
                # Print
                if reader.iter >= epoch * train_data.shape[0] - self.batch_size:
                    if self.folder is not None:
                        self.save(self.folder + "epoch" + str(epoch) + "/" + \
                                  str(self.model_name) + ".ckpt")
                    reader.pbar.write("Epoch %d" % epoch)
                    reader.pbar.write(" Training loss: %.6f" %
                                      (avg_train_loss / nb_batch))
                    if valid_data is not None:
                        bleu = self.evaluate(valid_data)
                        reader.pbar.write(" Validation bleu score: %.6f" %
                                          bleu)
                    epoch += 1
                    avg_train_loss = 0
                    nb_batch = 0
            except tf.errors.OutOfRangeError:
                reader.pbar.close()
                break
Esempio n. 26
0
def sendEmail(user_settings):
    while True:
        #if not sunday - return
        weekday = datetime.today().weekday()
        time =  datetime.now()
        hour = time.hour
        minute = time.minute
        second = time.second
        
        if weekday == 6 and hour == 12 and minute == 0 and second == 0:
            pass
        else: 
            continue

        config_path, db_path, _ = user_settings()
        with open(config_path, 'r') as file:
            config_settings = list(csv.reader(file))
            strTos = config_settings[3]
            strTos = list(filter(('Email').__ne__, strTos))


        # Define these once; use them twice!
        strFrom = '*****@*****.**'

        ###########
        
        #we need to edit this so that it takes from GUI
        #we will DEFINITELY have to 'import GUI'

        ###########
        sec_per_week = 7 * 24 * 60 * 60
        tsamp = 1
        nsamp = 5
        information = Reader(db_path,'sensor_db.db').get_timeset(table="SensorData", num= sec_per_week / (tsamp * nsamp)) #num is the number of data points. We need to figure out what num is for a whole week
        #Daniel will apply SQL lite later
    
        def func1(x):
            return x[1:]
        
        information = list(map(func1,information))
        #print('information')
        #print(information)

        param_list = ['pH', 'TDS (ppm)', 'Rela. Humidity (%)', 'Air Temp (\N{DEGREE SIGN}C)', 'Water Temp (\N{DEGREE SIGN}C)', 'Water Level (cm)']
        plt.figure(figsize = (12,12))
        plt.suptitle('Weekly Stats', fontsize = 30)
        #allOfData = {}
        for i in range(len(param_list)):
            def func2(x):
                return x[i]
            
            partOfInfo = list(map(func2,information))
            #print('part of info')
            #print(partOfInfo)
            #allOfData[param_list[i]] = partOfInfo
            plt.subplot(2,3,1+i)
            plt.plot(partOfInfo)
            plt.title(param_list[i])
            ax = plt.gca()
            ax.axes.xaxis.set_visible(False)
        
        title = 'thisweek.png'

        plt.tight_layout()
        plt.savefig(title)


        for strTo in strTos:
            # Create the root message and fill in the from, to, and subject headers
            msgRoot = MIMEMultipart('related')
            msgRoot['Subject'] = 'NU-ESW Aquaponics Weekly Update'
            msgRoot['From'] = strFrom
            msgRoot['To'] = strTo
            msgRoot.preamble = 'This is a multi-part message in MIME format.'

            # Encapsulate the plain and HTML versions of the message body in an
            # 'alternative' part, so message agents can decide which they want to display.
            msgAlternative = MIMEMultipart('alternative')
            msgRoot.attach(msgAlternative)

            msgText = MIMEText('This is the alternative plain text message.')
            msgAlternative.attach(msgText)




            
            #num needs to be changed accordingly
            

            # We reference the image in the IMG SRC attribute by the ID we give it below
            #msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>Nifty!', 'html')
            msgText = MIMEText('<b>Here are the graphs for the weekly values.</b><br><img src="cid:image1"><br>', 'html')
            msgAlternative.attach(msgText)

            # This example assumes the image is in the current directory

            fp = open(title, 'rb')
            msgImage = MIMEImage(fp.read())
            fp.close()

            # Define the image's ID as referenced above
            msgImage.add_header('Content-ID', '<image1>')
            msgRoot.attach(msgImage)

            
            
            
            
            
            #otherwise it goes here
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            # Send the email (this example assumes SMTP authentication is required)
            
            email = strFrom
            smtp = 'smtp.gmail.com'
            port = 587
            password = '******'
            server = smtplib.SMTP(smtp, port)

            server.starttls()

            server.login(email,password)
            server.sendmail(email, strTo, msgRoot.as_string())
            

        os.remove(title)