Beispiel #1
0
def db_create(trigger,username):
    if username:
        dbname="GW_"+str(trigger)+"_"+str(username)
    else:
        import random
        dbname="GW_"+str(trigger)+"_"+str(random.randint(0,999))
    command = ["CREATE TABLE `"+str(dbname)+"` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`triggername` text,`number` int(11) DEFAULT NULL,`SN` int(11) DEFAULT NULL,`NSN` int(11) DEFAULT NULL,`other` text, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=latin1"]
    try:
        sqlconn.query(command,sqlconn.conn)
        return dbname
    except:
        print "Table gcn_"+str(ligoid)+" already exists, insert directly!"
        return False
Beispiel #2
0
def info():
    command = [
        'select username from users where id=' + str(session['user_id'])
    ]
    data = sqlconn.query(command, sqlconn.conn)
    username = data[0]['username']
    return render_template("info.html", name=username)
Beispiel #3
0
def myaccount():
    command = [
        'select username from users where id=' + str(session['user_id'])
    ]
    data = sqlconn.query(command, sqlconn.conn)
    username = data[0]['username']
    if request.method == 'GET':
        command = [
            'select * from users_information where username="******"'
        ]
        data = sqlconn.query(command, sqlconn.conn)
        if not data:
            dictionary = {'username': str(username)}
            sqlconn.insert_values(sqlconn.conn, 'users_information',
                                  dictionary)
        return render_template('myaccount.html', inlist=data)
    elif request.method == 'POST':
        command = [
            'delete from users_information where username ="******"'
        ]
        sqlconn.query(command, sqlconn.conn)
        result = request.form
        dictionary = {
            'username': str(username),
            'gender': str(result['gender']),
            'month': str(result['month_start']),
            'year': str(result['year_start']),
            'day': str(result['day_start']),
            'location': str(result['location']) + '@' + str(result['country']),
            'email': str(result['email']),
            'zipcode': str(result['zipcode']),
            'work': str(result['work']),
            'phone': str(result['telephone'])
        }
        sqlconn.insert_values(sqlconn.conn, 'users_information', dictionary)
        command = [
            'select * from users_information where username="******"'
        ]
        data = sqlconn.query(command, sqlconn.conn)
        return render_template('myaccount.html', inlist=data)
Beispiel #4
0
def result():
    if 'user_id' in session:
        command = [
            'select username from users where id=' + str(session['user_id'])
        ]
        data = sqlconn.query(command, sqlconn.conn)
        username = data[0]['username']
    else:
        username = '******'
    return render_template("grawita_result.html",
                           user=username,
                           tlist=piclist.keys())
Beispiel #5
0
def gwshow_trigger(trig, num):
    if request.method == 'GET':
        numtotal = len(piclist[trig[1:]])
        pic = piclist[trig[1:]][num]
        return render_template('grawita_trigger.html',
                               trigger=trig,
                               num=num,
                               pic=pic,
                               numtotal=numtotal)

    elif request.method == 'POST':
        if 'user_id' in session:
            command = [
                'select username from users where id=' +
                str(session['user_id'])
            ]
            data = sqlconn.query(command, sqlconn.conn)
            username = data[0]['username']
            dbname = function.db_create(str(trig), username)
        result = request.form
        no, nsn, nnsn = '', 0, 0
        try:
            if result['sn']:
                if result['sn'] == 'on': nsn += 1
        except:
            pass
        try:
            if result['nsn']:
                if result['nsn'] == 'on': nnsn += 1
        except:
            pass
        try:
            if result['Other opinion']:
                no = result['Other opinion']
        except:
            pass
        dictionary = {
            'triggername': str(trig),
            'number': str(num),
            'SN': str(nsn),
            'NSN': str(nnsn),
            'other': str(no)
        }
        sqlconn.insert_values(sqlconn.conn, dbname, dictionary)
        numtotal = len(piclist[trig[1:]])
        pic = piclist[trig[1:]][num]
        return render_template('grawita_trigger.html',
                               trigger=trig,
                               num=num + 1,
                               pic=pic,
                               numtotal=numtotal)
Beispiel #6
0
def dltshow(trigger):
    import sqlconn
    command = ['select * from gcn_' + str(trigger)]
    data = sqlconn.query(command, sqlconn.conn)
    result = {}
    for i in range(len(data)):
        result[i] = []
        result[i].append(data[i]['name'])
        result[i].append(data[i]['distance'])
        result[i].append(data[i]['bmag'])
        result[i].append(data[i]['kmag'])
        result[i].append(data[i]['obs_window'])
        result[i].append(data[i]['ra0'])
        result[i].append(data[i]['dec0'])
    return render_template('dlt40.html', result=result)
Beispiel #7
0
import sqlconn
import glob
import numpy as np
import re
import os
import string
import sys

option = '2'

if option=='1':   
#    command = ['select t.ra0,t.dec0,t.distance,t.Bmagabs,t.Kmagabs,t.ebv,t.morphtype from targets as t']
    command = ['select * from gcn']
    data = sqlconn.query(command,sqlconn.conn)
    for i in range(len(data)):
        print data[i]['name']
if option=='2':
    ascfile=glob.glob('/Users/sheng.yang/ownCloud/dlt40/gcn/gcn_*.txt')
    for ascifile in ascfile:
        name,ra,dec,dist,bmag,kmag,obs=[],[],[],[],[],[],[]
        ligoid=re.search(r'G\w\w\w\w\w\w*',str(os.path.basename(ascifile))).group(0)

        # create table
        command = ["CREATE TABLE `gcn_"+str(ligoid)+"` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`name` text,`ra0` int(11) DEFAULT NULL,`dec0` int(11) DEFAULT NULL,`distance` int(11) DEFAULT NULL,`kmag` int(11) DEFAULT NULL,`bmag` int(11) DEFAULT NULL,`obs_window` text,PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=latin1"]
        try:
            sqlconn.query(command,sqlconn.conn)
        except:
            print "Table gcn_"+str(ligoid)+" already exists"
            continue
        
        test=open(ascifile).readlines()
Beispiel #8
0
def result1(user, trigger):
    dbname = "GW_" + str(trigger) + "_" + str(user)
    command = ['select * from ' + dbname]
    data = sqlconn.query(command, sqlconn.conn)
    return render_template("grawita_result1.html", result=data)