Example #1
0
def showsuite_rating(stid=None):
    session_init(session, db)

    for st in db.filtered_query('suite'):
        if st.id == stid:
            stname, notes, _pid = st.name, st.notes, st.person_id
    if stname is None:
        error = 'Could not find Suite #%i' % stid
        return render_template('ptable.html', error=error)

    ratings = []
    for score, review, dtime, pid in suite_ratings(db, stid):
        person = db.get_person(pid)
        ratings.append({
            'score': score,
            'review': multiline_text(review),
            'date': fmttime(dtime),
            'person_email': person.email,
            'person_name': person.name,
            'person_affil': person.affiliation
        })

    return render_template('show_suite_ratings.html',
                           ratings=ratings,
                           suite_notes=notes,
                           suite_name=stname)
def showspectrum_rating(spid=None):
    session_init(session, db)
    s  = db.get_spectrum(spid)
    if s is None:
        error = 'Could not find Spectrum #%i' % spid
        return render_template('ptable.html', error=error)

    opts = parse_spectrum(s, db)
    ratings = []
    for score, review, dtime, pid in spectrum_ratings(db, spid):
        person = db.get_person(pid)
        ratings.append({'score': score,
                        'review': multiline_text(review),
                        'date': fmttime(dtime),
                        'person_email': person.email,
                        'person_name': person.name,
                        'person_affil': person.affiliation})

    return render_template('show_spectrum_ratings.html',
                           ratings=ratings,
                           spectrum_name=opts['spectrum_name'])
def showsuite_rating(stid=None):
    session_init(session, db)

    for st in db.filtered_query('suite'):
        if st.id == stid:
            stname, notes, _pid = st.name, st.notes, st.person_id
    if stname is None:
        error = 'Could not find Suite #%i' % stid
        return render_template('ptable.html', error=error)

    ratings = []
    for score, review, dtime, pid in suite_ratings(db, stid):
        person = db.get_person(pid)
        ratings.append({'score': score, 'review': multiline_text(review),
                        'date': fmttime(dtime),
                        'person_email': person.email,
                        'person_name': person.name,
                        'person_affil': person.affiliation})

    return render_template('show_suite_ratings.html',
                           ratings=ratings, suite_notes=notes,
                           suite_name=stname)
Example #4
0
def showspectrum_rating(spid=None):
    session_init(session, db)
    s = db.get_spectrum(spid)
    if s is None:
        error = 'Could not find Spectrum #%i' % spid
        return render_template('ptable.html', error=error)

    opts = parse_spectrum(s, db)
    ratings = []
    for score, review, dtime, pid in spectrum_ratings(db, spid):
        person = db.get_person(pid)
        ratings.append({
            'score': score,
            'review': multiline_text(review),
            'date': fmttime(dtime),
            'person_email': person.email,
            'person_name': person.name,
            'person_affil': person.affiliation
        })

    return render_template('show_spectrum_ratings.html',
                           ratings=ratings,
                           spectrum_name=opts['spectrum_name'])
Example #5
0
def parse_spectrum(s, db):
    edge   = db.get_edge(s.edge_id)
    elem   = db.get_element(s.element_z)
    person = db.get_person(s.person_id)
    eunits = db.filtered_query('energy_units', id=s.energy_units_id)[0].units
    d_spacing = '%f'% s.d_spacing
    notes =  json.loads(s.notes)

    beamline_id, beamline_desc = beamline_for_spectrum(db, s, notes)
    citation_id, citation_name = citation_for_spectrum(db, s, notes)

    try:
        sample = db.filtered_query('sample', id=s.sample_id)[0]
        sample_id = '%i'% s.sample_id
        sample_name = sample.name
        sample_form = sample.formula
        sample_prep = sample.preparation
    except:
        sample_id  = '-1'
        sample_name = 'unknown'
        sample_form = 'unknown'
        sample_prep = 'unknown'
        if 'sample' in notes:
            sample_name = notes['sample']
            if isinstance(sample_name, dict):
                sample_name = dict_repr(sample_name)

    # reference sample
    refer_id = '-1'
    refer_name = ''
    if s.reference_id is not None:
        rsample = db.filtered_query('sample', id=s.reference_id)[0]
        refer_id = s.reference_id
        refer_name = rsample.name

    mononame = 'unknown'
    if 'mono' in notes:
        if 'name' in notes['mono']:
            mononame = notes['mono']['name']

    notes.pop('column')
    notes.pop('scan')
    notes.pop('element')

    misc = []
    for key, val in notes.items():
        if isinstance(val, dict):
            val = dict_repr(val).strip()
        if len(val) > 1:
            misc.append({'key': "# %s" % key.title(), 'val': val})

    return {'spectrum_id': s.id,
            'spectrum_name': s.name,
            'elem_sym': elem.symbol,
            'elem_name': elem.name,
            'edge': edge.name,
            'energy_units': eunits,
            'raw_comments': s.comments,
            'comments': multiline_text(s.comments),
            'beamline_id': beamline_id,
            'beamline_desc': beamline_desc,
            'citation_id': citation_id,
            'citation_name': citation_name,
            'mononame': mononame,
            'd_spacing': d_spacing,
            'misc': misc,
            'sample_id':   sample_id,
            'sample_name':  sample_name,
            'sample_form':  sample_form,
            'sample_prep':  sample_prep,
            'refer_id': "%i" % int(refer_id),
            'refer_name': refer_name,
            'person_email': person.email,
            'person_name': person.name,
            'upload_date': fmttime(s.submission_date),
            'collection_date': fmttime(s.collection_date),
            'xdi_filename': "%s.xdi" % (s.name.strip()),
            'fullfig': None,
            'xanesfig': None}
Example #6
0
def parse_spectrum(s, db):
    edge = db.get_edge(s.edge_id)
    elem = db.get_element(s.element_z)
    person = db.get_person(s.person_id)
    eunits = db.filtered_query("energy_units", id=s.energy_units_id)[0].units
    d_spacing = "%f" % s.d_spacing
    notes = json.loads(s.notes)

    beamline_id, beamline_desc = beamline_for_spectrum(db, s, notes)
    citation_id, citation_name = citation_for_spectrum(db, s, notes)

    try:
        sample = db.filtered_query("sample", id=s.sample_id)[0]
        sample_id = "%i" % s.sample_id
        sample_name = sample.name
        sample_form = sample.formula
        sample_prep = sample.preparation
    except:
        sample_id = "-1"
        sample_name = "unknown"
        sample_form = "unknown"
        sample_prep = "unknown"
        if "sample" in notes:
            sample_name = notes["sample"]
            if isinstance(sample_name, dict):
                sample_name = dict_repr(sample_name)

    # reference sample
    refer_id = "-1"
    refer_name = ""
    if s.reference_id is not None:
        rsample = db.filtered_query("sample", id=s.reference_id)[0]
        refer_id = s.reference_id
        refer_name = rsample.name

    mononame = "unknown"
    if "mono" in notes:
        if "name" in notes["mono"]:
            mononame = notes["mono"]["name"]

    notes.pop("column")
    notes.pop("scan")
    notes.pop("element")

    misc = []
    for key, val in notes.items():
        if isinstance(val, dict):
            val = dict_repr(val).strip()
        if len(val) > 1:
            misc.append({"key": "# %s" % key.title(), "val": val})

    return {
        "spectrum_id": s.id,
        "spectrum_name": s.name,
        "elem_sym": elem.symbol,
        "elem_name": elem.name,
        "edge": edge.name,
        "energy_units": eunits,
        "raw_comments": s.comments,
        "comments": multiline_text(s.comments),
        "beamline_id": beamline_id,
        "beamline_desc": beamline_desc,
        "citation_id": citation_id,
        "citation_name": citation_name,
        "mononame": mononame,
        "d_spacing": d_spacing,
        "misc": misc,
        "sample_id": sample_id,
        "sample_name": sample_name,
        "sample_form": sample_form,
        "sample_prep": sample_prep,
        "refer_id": "%i" % int(refer_id),
        "refer_name": refer_name,
        "person_email": person.email,
        "person_name": person.name,
        "upload_date": fmttime(s.submission_date),
        "collection_date": fmttime(s.collection_date),
        "xdi_filename": "%s.xdi" % (s.name.strip()),
        "fullfig": None,
        "xanesfig": None,
    }