Commit 6ac8e3b6 authored by Takhir Fakhrutdinov's avatar Takhir Fakhrutdinov

Загрузка файлов ЕОР

parent e7a84a82
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,6 +4,7 @@ import hashlib as hs
import logging
import json
import io
import sys
logger = logging.getLogger('')
......@@ -50,7 +51,33 @@ class msFile(measFile):
if _loaded:
head = json.dumps(t.params,default=_2json,separators=(',', ':',))
_id = await self.fetchval("select * from nextval('xd.t_tracks_track_seq'::regclass)")
eop = t.eop if 'eop' in t._fileds else r'\N'
if 'eop' in t._fields:
# сохраняем имена файлов
async with self.transaction():
await self.execute("""
insert into xd.t_nfstank(dev,night,fn)
select $1,$2,fn
from unnest($3::text[]) fn
on conflict do nothing
""",dev,night,t.files)
# получаем идентификаторы файлов
foid = await self.fetchval("""
with sf as (
select $1::integer dev,$2::date::timestamp night,fn,rn
from unnest($3::text[]) with ordinality v(fn,rn)
)
select array_agg(foid order by rn)
from xd.t_nfstank join sf using(dev,night,fn)
""",dev,night,t.files)
_ = list()
for i in range(len(foid)):
_.append(r'"({},\\"{}\\")"'.format(foid[i],json.dumps(t.eop[i],default=_2json,separators=(',', ':',)).replace('"',r'\\"\\"')))
eop = '{%s}' % ','.join(_)
else:
eop = r'\N'
self.write(fo,(_id,t.tm,dev,vc,t.utr,t.meas,head,night,eop))
tracks_crc[t.crc] = dict(track=_id,tm=t.tm)
else:
......
......@@ -12,7 +12,7 @@ track_list = {'sigma':float,'distrust':bool,'fake':bool}
bind_list = {'time':float,'id':int,'along':float,'across':float,'dmag':float}
meas_list = {'ra_j2000':float,'dec_j2000':float,'mag':float,'ra_j2000_full_error':float,'dec_j2000_full_error':float,'mag_error':float,}
eop_list = {'ra_j2000_error':float,'dec_j2000_error':float,'x':float,'x_error':float,'y':float,'y_error':float,
'fwhm_x',float,'fwhm_x_error':float,'fwhm_y':float,'fwhm_y_error':float,
'fwhm_x':float,'fwhm_x_error':float,'fwhm_y':float,'fwhm_y_error':float,
'rot':float,'snr':float,'peak_snr':float,'flux':float,'ins_mag':float,'aper_width':float,'aper_height':float,
'channel':float,'filter':str,
}
......@@ -91,7 +91,7 @@ def _get_meas_t(meas):
mag = float(m.get('mag',0.0))
if mag != 0: mags.append(mag)
eop.append(json.dumps({k:f(t[k]) for k,f in eop_list.items() if k in t and t.get(k) is not None}))
eop.append({k:f(m[k]) for k,f in eop_list.items() if k in m and m.get(k) is not None})
if 'crops' in m:
crops = r'\\\\\\\\x%s' % base64.b64decode(m['crops']).hex()
ms.append(r'"(\\"%s\\",\\"%s\\",\\"%s\\")"' % (tm.isoformat(),str(rec).replace('[','{').replace(']','}'),crops,))
......@@ -99,7 +99,7 @@ def _get_meas_t(meas):
ms.append(r'"(\\"%s\\",\\"%s\\",)"' % (tm.isoformat(),str(rec).replace('[','{').replace(']','}'),))
avg_m = round(sum(mags)/len(mags),1) if len(mags) else 0.0
return tb,te,avg_m,'{%s}' % ','.join(ms),files,'{%s}' % ','.join(eop)
return tb,te,avg_m,'{%s}' % ','.join(ms),files,eop
def parsefile(f):
tracks,tbeg,tend,mcnt = list(),datetime.max,datetime.min,0
......@@ -108,21 +108,22 @@ def parsefile(f):
for t in data['tracks']:
if not siteid: siteid = t['siteid']
b = t.get('bind')
tb,te,avg_m,ms,files,eop = _get_meas_t(t['meas'])
tbeg,tend,cnt = min(tbeg,tb),max(tend,te),len(t['meas'])
mcnt += cnt
# Формируем проводку
params = {k:f(t[k]) for k,f in track_list.items() if k in t and t.get(k) is not None}
params.update(dict(bind={k:f(t[k]) for k,f in bind_list.items() if k in t and t.get(k) is not None}))
params.update(dict(bind={k:f(b[k]) for k,f in bind_list.items() if k in b and b.get(k) is not None}))
params.update(dict(cnt=cnt,mag=avg_m,obj=t['trackid'],area=t.get('target')))
tr = dict(
tm=te,
meas=ms,
utr='["%s","%s"]' % (tb,te,),
crc=_get_trackcrc(t['meas']),
params=params
eop=eop
files=files
params=params,
eop=eop,
files=files,
)
tracks.append(namedtuple('track_t',tr.keys())(**tr))
......
......@@ -161,9 +161,9 @@ class baseFile(Connection):
self.log.seek(0)
self.fileattr.update(dict(log=self.log.read(),subj=self.args.subject,rem=self.args.comment))
# Нужна внешняя транзакция
if hasattr(self,'devs'):
forecast = await self.fetchval(self.FORECAST_SQL,self.devs[0],self.tbeg)
self.fileattr['wd'] = forecast
#if hasattr(self,'devs'):
# forecast = await self.fetchval(self.FORECAST_SQL,self.devs[0],self.tbeg)
# self.fileattr['wd'] = forecast
await self.execute("""
insert into main.t_files(fid,tm,state,ftype,usename,prefix,fname,crc,utr,tels,params)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment