Beispiel #1
0
def addplot():
    if not current_user.check_roles(['admin', 'water']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    plotname = request.form['plotname']
    plot = Waterplot.query.filter_by(plotname=plotname).first()
    if plot:
        return 'fail1'
    latdegree = request.form['latdegree']
    latminute = request.form['latminute']
    latsecond = request.form['latsecond']
    londegree = request.form['londegree']
    lonminute = request.form['lonminute']
    lonsecond = request.form['lonsecond']
    watershedid = request.form['watershedid']
    plot=Waterplot(watershed_id=watershedid,\
     plotname=plotname,\
     latdegree=latdegree,\
     latminute=latminute,\
     latsecond=latsecond,\
     londegree=londegree,\
     lonminute=lonminute,\
     lonsecond=lonsecond)
    db.session.add(plot)
    db.session.commit()
    plots = Waterplot.query.order_by(Waterplot.plotname).all()
    return render_template('water/_plots.html', datas=plots)
Beispiel #2
0
def clearvoctype():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	cleardata(Voctype)
	flash('已清空VOC类型数据')
	return redirect(url_for('air.airdata'))
Beispiel #3
0
def download_vocexample():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	filename='airdata_example.xlsx'
	filepath=os.path.join(current_app.config['DOWNLOAD_FOLDER'])
	return send_from_directory(directory=filepath, filename=filename)
Beispiel #4
0
def clearairdata():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	cleardata(Airdata)
	flash('已清空常规空气质量数据')
	return redirect(url_for('air.airdata'))
Beispiel #5
0
def clearvocdata():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	cleardata(Vocdata)
	flash('已清空挥发性有机物数据')
	return redirect(url_for('air.vocdata'))
Beispiel #6
0
def users():
    if not current_user.check_roles(['admin']):
        flash('非系统管理员用户无权访问该页面')
        return redirect(url_for('main.index'))
    form = UsersForm()
    form.role.choices = [(item.id, item.description)
                         for item in Role.query.all()]
    if request.method == 'POST' and form.action.data:
        if form.action.data == 1:  #action: '1' for EDIT, '2' for 'DELETE'
            user = User.query.filter_by(id=form.id.data).first()
            if user is None:
                flash('找不到指定的用户,编辑失败.')
            else:
                role = Role.query.filter_by(id=form.role.data).first()
                if role is None:
                    flash('找不到指定的角色,编辑失败.')
                else:
                    user.roles[0] = role
                    db.session.commit()
                    flash('用户 <{}> 的角色已更改为({}).'.format(
                        user.username, role.description))
        else:
            user = User.query.filter_by(id=form.id.data).first()
            if user is None:
                flash('找不到指定的用户,编辑失败.')
            else:
                db.session.delete(user)
                db.session.commit()
                flash('用户 <{}> 账户已删除.'.format(user.username))
    users = User.query.all()
    return render_template('auth/users.html',
                           title="用户账户管理",
                           users=users,
                           form=form)
Beispiel #7
0
def quadrat():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    form = QuadratForm()
    form.plot.choices = [(plot.id, plot.plotname)
                         for plot in Forestplot.query.all()]
    if form.validate_on_submit():
        number = form.number.data
        existquadrat = Herbquadrat.query.filter(
            Herbquadrat.number == number,
            Herbquadrat.forestplot_id == form.plot.data).first()
        if existquadrat:
            flash('样地 <{}> 已存在样方编号 <{}>,样方添加失败.'.format(
                existquadrat.plot.plotname, str(number)))
        else:
            quadrat = Herbquadrat(number=number, forestplot_id=form.plot.data)
            db.session.add(quadrat)
            db.session.commit()
            flash('样方 <编号:{}> 已成功添加至样地 <{}>'.format(str(number),
                                                    quadrat.plot.plotname))
    quadrats = Herbquadrat.query.join(Herbquadrat.plot).order_by(
        Forestplot.plotname, Herbquadrat.number).all()
    return render_template('forest/quadrat.html',
                           title='样方管理',
                           quadrats=quadrats,
                           form=form)
Beispiel #8
0
def indicator():
	if not current_user.check_roles(['admin','soil']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	form=SoilindicatorForm()
	form.indicatortype.choices=[('其它','其它'),('重金属','重金属'),('多环芳烃','多环芳烃')]
	if request.method=='POST' and (form.action.data is not None):
		if form.action.data==2:#action:  '1' for EDIT, '2' for 'DELETE'
			indicator=Soilindicator.query.filter_by(id=form.id.data).first()
			if indicator is None:
				flash('指标项删除失败!')
			else:
				for data in indicator.soildatas:
					db.session.delete(data)
				db.session.delete(indicator)
				db.session.commit()
				flash('土壤监测指标项 <{}> 删除成功!'.format(indicator.indicatorname))
		elif form.action.data==1:
			indicator=Soilindicator.query.filter_by(id=form.id.data).first()
			if indicator:
				indicator.symbol=form.symbol.data
				indicator.unit=form.unit.data
				indicator.dland_standard=form.dland_standard.data
				indicator.aland_standard_ph1=form.aland_standard_ph1.data
				indicator.aland_standard_ph2=form.aland_standard_ph2.data
				indicator.aland_standard_ph3=form.aland_standard_ph3.data
				indicator.aland_standard_ph4=form.aland_standard_ph4.data
				indicator.indicatortype=form.indicatortype.data
				db.session.commit()
				flash('土壤监测指标项 <{}> 编辑成功!'.format(indicator.indicatorname))
			else:
				flash('土壤监测指标项编辑失败!')
	indicators=Soilindicator.query.order_by(Soilindicator.indicatortype,Soilindicator.indicatorname).all()
	return render_template('soil/indicator.html',title='土壤监测指标项信息',indicators=indicators, form=form)
Beispiel #9
0
def newusers():
	if not current_user.check_roles(['admin']):
		flash('非系统管理员用户无权访问该页面')
		return redirect(url_for('main.index'))
	newusers=Register.query.filter_by(verified=1).all()
	print(newusers)
	return render_template('auth/newusers.html',title='用户审核',newusers=newusers)
Beispiel #10
0
def editplot():
    if not current_user.check_roles(['admin', 'water']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    plotid = request.form['plotid']
    plotname = request.form['plotname']
    plot = Waterplot.query.filter(Waterplot.plotname == plotname,
                                  Waterplot.id != plotid).first()
    if plot:
        return 'fail1'
    plot = Waterplot.query.filter_by(id=plotid).first()
    if plot is None:
        return 'fail2'
    latdegree = request.form['latdegree']
    latminute = request.form['latminute']
    latsecond = request.form['latsecond']
    londegree = request.form['londegree']
    lonminute = request.form['lonminute']
    lonsecond = request.form['lonsecond']
    plot.plotname = plotname
    plot.latdegree = latdegree
    plot.latminute = latminute
    plot.latsecond = latsecond
    plot.londegree = londegree
    plot.lonminute = lonminute
    plot.lonsecond = lonsecond
    db.session.commit()
    plots = Waterplot.query.order_by(Waterplot.plotname).all()
    return render_template('water/_plots.html', datas=plots)
Beispiel #11
0
def airdatas():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	page=request.args.get('page',1,type=int)
	startstr=request.args.get('timestart','',type=str)
	endstr=request.args.get('timeend','',type=str)
	plotid=request.args.get('plotid','-1',type=int)
	if startstr.strip()=='':
		timestart=datetime(1990,1,1,0,0)
	else:
		timestart=datetime.strptime(startstr,'%Y-%m-%d %H:%M:%S')
	if endstr.strip()=='':
		timeend=datetime(4000,1,1,0,0)
	else:
		timeend=datetime.strptime(endstr,'%Y-%m-%d %H:%M:%S')
	if plotid>=0:
		pagedatas=Airdata.query.filter(Airdata.airplot_id==plotid,Airdata.timestamp>=timestart,Airdata.timestamp<=timeend).order_by(Airdata.timestamp).paginate(page,current_app.config['POSTS_PER_PAGE'],False)
	else:
		pagedatas=Airdata.query.filter(Airdata.timestamp>=timestart,Airdata.timestamp<=timeend).order_by(Airdata.timestamp).paginate(page,current_app.config['POSTS_PER_PAGE'],False)
	pages=pagedatas.pages
	current_page=pagedatas.page
	next_num=pagedatas.next_num if pagedatas.has_next else None
	prev_num=pagedatas.prev_num if pagedatas.has_prev else None
	datas=pagedatas.items
	return render_template('air/_datas.html',datas=datas,next_num=next_num,prev_num=prev_num,pages=pages,current_page=current_page)
Beispiel #12
0
def clearplots():
	if not current_user.check_roles(['admin','soil']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	cleardata(Soildata)
	cleardata(Soilplot)
	flash('已清空土壤调查样地数据')
	return redirect(url_for('soil.plot'))
Beispiel #13
0
def deldata():
    if not current_user.check_roles(['admin', 'society']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    try:
        year = request.form['year']
        indicatorid = request.form['indicatorid']
        years = request.form['years']
        indicatorids = request.form['indicators']
        years = json.loads(years)
        indicatorids = json.loads(indicatorids)
        if year == '0':
            datas = Societydata.query.filter(
                Societydata.indicator_id == indicatorid,
                Societydata.year.in_(years)).all()
            if datas is None:
                return 'fail'
            else:
                for item in datas:
                    db.session.delete(item)
                db.session.commit()
        else:
            data = Societydata.query.filter(
                Societydata.indicator_id == indicatorid,
                Societydata.year == year).first()
            if data is None:
                return 'fail'
            else:
                db.session.delete(data)
                db.session.commit()
        societydatas = []
        indicators = []
        indicators = Societyindicator.query.filter(
            Societyindicator.id.in_(indicatorids)).order_by(
                Societyindicator.class_id, Societyindicator.id).all()
        for indicator in indicators:
            data = Societydata.query.filter_by(
                indicator_id=indicator.id).filter(
                    Societydata.year.in_(years)).all()
            if data:
                societydata = [indicator, data]
                societydatas.append(societydata)
        intyears = []
        existyear = None
        yeardatas = Societydata.query.filter(
            Societydata.year.in_(years)).order_by(Societydata.year).all()
        if len(yeardatas) > 0:
            existyear = yeardatas[0].year
            for item in yeardatas:
                if item.year != existyear:
                    intyears.append(existyear)
                existyear = item.year
            intyears.append(existyear)
        return render_template('society/_datas.html',
                               datas=societydatas,
                               years=intyears)
    except:
        return 'fail'
Beispiel #14
0
def arbor(plotid):
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    plot = Forestplot.query.filter_by(id=plotid).first()
    if plot is None:
        flash('查询样地数据不存在!')
        return redirect(url_for("forest.plot"))
    else:
        form = ArborForm()
        form.chnname.choices = [
            (arbortype.id, arbortype.chnname)
            for arbortype in Arbortype.query.order_by(Arbortype.chnname).all()
        ]
        if form.validate_on_submit():
            if form.id.data == 0:  #Add
                existarbor = Arbor.query.filter(
                    Arbor.number == form.number.data + plot.id * 1000000,
                    Arbor.plot == plot).first()
                if existarbor is None:
                    arbortype = Arbortype.query.filter_by(
                        id=form.chnname.data).first()
                    if arbortype:
                        arbor = Arbor(arbortype=arbortype,
                                      plot=plot,
                                      number=form.number.data +
                                      plot.id * 1000000)
                        db.session.add(arbor)
                        db.session.commit()
                        flash('树种数据 <编号:{}> 添加成功!'.format(form.number.data))
                    else:
                        flash('树种类型不存在,添加失败.')
                else:
                    flash('树种编号<{}>已存在,添加失败。'.format(str(form.number.data)))
            else:  #Edit
                arbortype = Arbortype.query.filter_by(
                    id=form.chnname.data).first()
                if arbortype:
                    arbor = Arbor.query.filter(
                        Arbor.number == form.number.data + plot.id * 1000000,
                        Arbor.plot == plot).first()
                    if arbor:
                        arbor.arbortype = arbortype
                        db.session.commit()
                        flash('树种数据 <编号:{}> 修改成功。'.format(form.number.data))
                    else:
                        flash('树种数据 <编号:{}> 编号不存在,修改失败。'.format(
                            form.number.data))
                else:
                    flash('树种类型不存在,数据修改失败.')
        arbors = Arbor.query.filter(Arbor.plot == plot).order_by(
            Arbor.number).all()
        return render_template('forest/arbor.html',
                               title="样地乔木数据管理",
                               plot=plot,
                               arbors=arbors,
                               form=form)
Beispiel #15
0
def delvocdata():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	try:
		plotid=request.form['plotid']
		time=request.form['time']
		typeid=request.form['typeid']
		plotids=request.form['plots']
		times=request.form['times']
		typeids=request.form['types']
		plotids=json.loads(plotids)
		timestrs=json.loads(times)
		typeids=json.loads(typeids)
		timestamp=datetime.strptime(time+'01日',"%Y年%m月%d日")
		if plotid=='0':
			datas=Vocdata.query.filter(Vocdata.voctype_id==typeid,Vocdata.timestamp==timestamp,Vocdata.airplot_id.in_(plotids)).all()
			if datas is None:
				return 'fail'
			else:
				for item in datas:
					db.session.delete(item)
				db.session.commit()
		else:
			data=Vocdata.query.filter(Vocdata.voctype_id==typeid,Vocdata.timestamp==timestamp,Vocdata.airplot_id==plotid).first()
			if data is None:
				return 'fail'
			else:
				db.session.delete(data)
				db.session.commit()
		datas=[]
		plots=Airplot.query.filter(Airplot.id.in_(plotids)).all()		
		times=[]
		for item in timestrs:
			times.append(datetime.strptime(item,"%Y-%m-%d"))
		dataquery=Vocdata.query.filter(Vocdata.timestamp.in_(times),Vocdata.airplot_id.in_(plotids),Vocdata.voctype_id.in_(typeids)).order_by(Vocdata.timestamp,Vocdata.voctype_id)
		vocdatas=dataquery.all()
		datarow=[]
		if len(vocdatas)>0:
			datarow=[]
			voctype_id=vocdatas[0].voctype_id
			timestamp=vocdatas[0].timestamp
			for data in vocdatas:
				if voctype_id==data.voctype_id and timestamp==data.timestamp:
					datarow.append(data)
				else:
					datas.append(datarow)
					datarow=[]
					datarow.append(data)
					voctype_id=data.voctype_id
					timestamp=data.timestamp
		if len(datarow)>0:
			datas.append(datarow)
		return render_template('air/_vocdatas.html',plots=plots,datas=datas)
	except:
		return 'fail'
Beispiel #16
0
def plot():
    if not current_user.check_roles(['admin', 'water']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    watersheds = Watershed.query.order_by(Watershed.rivername).all()
    plots = Waterplot.query.order_by(Waterplot.plotname).all()
    return render_template('water/plot.html',
                           title="水质监测点位管理",
                           datas=plots,
                           watersheds=watersheds)
Beispiel #17
0
def soilurl():
	if not current_user.check_roles(['admin']):
		flash('非系统管理员用户无权访问该页面')
		return redirect(url_for('main.index'))
	form=SoilshpForm()
	form.indicators.choices=[(item.id,item.indicatorname) for item in Soilindicator.query.all()]
	wdatas=Soildata.query.order_by(Soildata.year).all()
	form.years.choices=[]
	existyear=None
	if len(wdatas)>0:
		existyear=wdatas[0].year
		for item in wdatas:
			if item.year!=existyear:
				form.years.choices.append((existyear,existyear))
				existyear=item.year
		form.years.choices.append((existyear,existyear))
	wdatas=Soilplot.query.order_by(Soilplot.region).all()
	form.regions.choices=[]
	existregion=None
	if len(wdatas)>0:
		existregions=wdatas[0].region
		for item in wdatas:
			if item.region!=existregion:
				form.regions.choices.append((existregion,existregion))
				existregion=item.region
		form.regions.choices.append((existregion,existregion))
	if request.method=='POST' and (form.action.data is not None):
		if form.action.data==2:#action: '0' for ADD, '1' for EDIT, '2' for 'DELETE', '3' for excel file upload
			shp=Soilshp.query.filter_by(id=form.id.data).first()
			if shp is None:
				flash('链接删除失败!')
			else:
				indicatorname=shp.indicator.indicatorname
				db.session.delete(shp)
				db.session.commit()
				flash('指标 <{}> 链接删除成功!'.format(indicatorname))
		elif form.action.data==0:
			shp=Soilshp(indicator_id=form.indicators.data,\
				region=form.regions.data,\
				year=form.years.data,\
				shpurl=form.shp.data)
			db.session.add(shp)
			db.session.commit()
			flash('指标 <{}> 链接添加成功!'.format(shp.indicator.indicatorname))
		elif form.action.data==1:
			shp=Soilshp.query.filter_by(id=form.id.data).first()
			if shp:
				shp.shpurl=form.shp.data
				db.session.commit()
				flash('指标 <{}> 链接编辑成功!'.format(shp.indicator.indicatorname))
			else:
				flash('指标链接编辑失败!')
	shps=Soilshp.query.order_by(Soilshp.year,Soilshp.region,Soilshp.indicator_id).all()
	return render_template('map/soilurl.html',title='地图服务管理',shps=shps, form=form)
Beispiel #18
0
def delplot():
    if not current_user.check_roles(['admin', 'water']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    plotid = request.form['plotid']
    plot = Waterplot.query.filter_by(id=plotid).first()
    if plot is None:
        return 'fail1'
    db.session.delete(plot)
    db.session.commit()
    plots = Waterplot.query.order_by(Waterplot.plotname).all()
    return render_template('water/_plots.html', datas=plots)
Beispiel #19
0
def realdata():
    if not current_user.check_roles(['admin', 'water']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    server = 'dnuedatabase1.sqlserver.rds.aliyuncs.com:3433'
    user = '******'
    password = '******'
    database = 'nbwater_iot'
    conn = pymssql.connect(server, user, password, database)
    cursor = conn.cursor()
    form = WaterrealdataqueryForm()
    form.plots.choices = []
    cursor.execute('select id,plotname from plot')
    row = cursor.fetchone()
    while row:
        form.plots.choices.append((row[0], row[1]))
        row = cursor.fetchone()
    conn.close()
    time1 = datetime.now()
    time0 = time1 + timedelta(days=-1)
    timestartstr = time0.strftime('%Y-%m-%d %H:%M:%S')
    timeendstr = time1.strftime('%Y-%m-%d %H:%M:%S')
    datas = []
    if request.method == 'POST':
        if form.timestart.data.strip() != '':
            timestartstr = form.timestart.data
        if form.timeend.data.strip() != '':
            timeendstr = form.timeend.data
        if form.plots.data:
            plotid = form.plots.data
            try:
                timestart = datetime.strptime(timestartstr,
                                              '%Y-%m-%d %H:%M:%S')
                timeend = datetime.strptime(timeendstr, '%Y-%m-%d %H:%M:%S')
                conn = pymssql.connect(server, user, password, database)
                cursor = conn.cursor()
                cursor.execute(
                    "select dt,temp,ph,ORP,spCond,sal,depth,turbidity,LDO from data where dt>='{}' and dt<='{}' and plot_id={} order by dt"
                    .format(timestartstr, timeendstr, plotid))
                row = cursor.fetchone()
                while row:
                    datas.append((row[0], row[1], row[2], row[3], row[4],
                                  row[5], row[6], row[7], row[8]))
                    row = cursor.fetchone()
            finally:
                conn.close()
    else:
        form.timestart.data = timestartstr
        form.timeend.data = timeendstr
    return render_template('water/realdata.html',
                           title='水环境物联网监测数据',
                           form=form,
                           datas=datas)
Beispiel #20
0
def herb():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    #times=[sample.timestamp.strftime('%Y-%m-%d') for sample in Herbsample.query.group_by(Herbsample.timestamp).order_by(Herbsample.timestamp.desc()).all()]
    hsamples = Herbsample.query.order_by(Herbsample.timestamp.desc()).all()
    times = []
    etime = None
    if len(hsamples) > 0:
        etime = hsamples[0].timestamp
        for item in hsamples:
            if item.timestamp != etime:
                times.append(etime.strftime('%Y-%m-%d'))
                etime = item.timestamp
        times.append(etime.strftime('%Y-%m-%d'))
    if request.method == "GET":
        plotid = request.args.get('plotid')
        time = request.args.get('time')
    else:
        plotid = request.form['plotid']
        time = request.form['time']
        times.append(time)
        flash('调查日期<{}>添加成功.'.format(time))
    quadrats = Herbquadrat.query.filter_by(forestplot_id=plotid).order_by(
        Herbquadrat.number).all()
    if len(quadrats) == 0:
        flash('指定样地无样方信息,请先添加样方.')
        return redirect(url_for('forest.plot'))
    else:
        quadrat = quadrats[0]
        herbsample = None
        if len(times) > 0:
            if time is None:
                time = times[0]
            timestamp = datetime.strptime(time, '%Y-%m-%d')
            herbsample = Herbsample.query.filter(
                Herbsample.quadrat == quadrat,
                Herbsample.timestamp == timestamp).first()
        herbsampleform = HerbsampleForm()
        herbform = HerbForm()
        herbform.herbtype.choices = [(herbtype.id, herbtype.chnname)
                                     for herbtype in Herbtype.query.order_by(
                                         Herbtype.chnname.desc()).all()]
        return render_template('forest/herb.html',
                               title='草本植物调查数据',
                               times=times,
                               time=time,
                               quadrats=quadrats,
                               quadrat=quadrat,
                               herbsample=herbsample,
                               herbsampleform=herbsampleform,
                               herbform=herbform)
Beispiel #21
0
def rejectnewuser():
	if not current_user.check_roles(['admin']):
		flash('非系统管理员用户无权访问该页面')
		return redirect(url_for('main.index'))
	register_id=request.form['id']
	register=Register.query.filter_by(id=register_id).first()
	if register is None:
		return 'fail'
	else:
		db.session.delete(register)
		db.session.commit()
		send_reject_email(register)
		newusers=Register.query.filter_by(verified=1).all()
		return render_template('auth/_newusers.html',newusers=newusers)
Beispiel #22
0
def delherbsample():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    herb_id = request.form['id']
    herb = Herb.query.filter_by(id=herb_id).first()
    if herb is None:
        return 'fail@删除失败:找不到指定的草本植被数据'
    else:
        herbsample = herb.sample
        db.session.delete(herb)
        db.session.commit()
        return render_template('forest/_herbsinsample.html',
                               herbsample=herbsample)
Beispiel #23
0
def delquadratsample():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    sample_id = request.form['id']
    quadratsample = Herbsample.query.filter_by(id=sample_id).first()
    if quadratsample is None:
        return 'fail@删除失败:找不到指定的样方调查数据.'
    else:
        for herbsample in quadratsample.herbs:
            db.session.delete(herbsample)
        db.session.delete(quadratsample)
        db.session.commit()
        return '<span>所选调查时间内没有数据,</span><a href="#" data-toggle="modal" data-target="#addsampleModal">添加数据?</a>'
Beispiel #24
0
def delherbtype():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    typeid = request.form['id']
    name = request.form['name']
    herbtype = Herbtype.query.filter_by(id=typeid).first()
    if herbtype is None:
        return 'fail'
    else:
        db.session.delete(herbtype)
        db.session.commit()
        herbtypes = Herbtype.query.order_by(Herbtype.chnname).all()
        return render_template('forest/_typedatas.html', typedatas=herbtypes)
Beispiel #25
0
def delquadrat():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    del_id = request.form['id']
    quadrat = Herbquadrat.query.filter_by(id=del_id).first()
    if quadrat:
        db.session.delete(quadrat)
        db.session.commit()
        quadrats = Herbquadrat.query.join(Herbquadrat.plot).order_by(
            Forestplot.plotname, Herbquadrat.number).all()
        return render_template('forest/_quadrats.html', quadrats=quadrats)
    else:
        return 'fail'
Beispiel #26
0
def plot():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	form=AirplotForm()
	if request.method=='POST' and (form.action.data is not None):
		if form.action.data==2:#action: '0' for ADD, '1' for EDIT, '2' for 'DELETE'
			plot=Airplot.query.filter_by(id=form.id.data).first()
			if plot is None:
				flash('点位删除失败!')
			else:
				for data in plot.airdatas:
					db.session.delete(data)
				for data in plot.vocdatas:
					db.session.delete(data)
				db.session.delete(plot)
				db.session.commit()
				flash('空气质量监测点位 <{}> 及其相关数据删除成功!'.format(plot.plotname))
		elif form.action.data==0:
			plot=Airplot(plotname=form.plotname.data,\
				landtype=form.landtype.data,\
				samplefrequency=form.samplefrequency.data,\
				latdegree=form.latdegree.data,\
				latminute=form.latminute.data,\
				latsecond=form.latsecond.data,\
				londegree=form.londegree.data,\
				lonminute=form.lonminute.data,\
				lonsecond=form.lonsecond.data)
			db.session.add(plot)
			db.session.commit()
			flash('空气质量监测点位 <{}> 添加成功!'.format(form.plotname.data))
		elif form.action.data==1:
			plot=Airplot.query.filter_by(id=form.id.data).first()
			if plot:
				plot.landtype=form.landtype.data
				plot.samplefrequency=form.samplefrequency.data
				plot.latdegree=form.latdegree.data
				plot.latminute=form.latminute.data
				plot.latsecond=form.latsecond.data
				plot.londegree=form.londegree.data
				plot.lonminute=form.lonminute.data
				plot.lonsecond=form.lonsecond.data
				db.session.commit()
				flash('空气质量监测点位 <{}> 编辑成功!'.format(form.plotname.data))
			else:
				flash('点位信息编辑失败!')
	plots=Airplot.query.order_by(Airplot.plotname).all()
	return render_template('air/airplots.html',title='空气质量监测站点管理',plots=plots, form=form)
Beispiel #27
0
def airdata():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	form=DataQueryForm()
	#form.plots.choices=[(item.plot.id,item.plot.plotname) for item in Airdata.query.group_by(Airdata.airplot_id).order_by(Airdata.airplot_id).all()]
	airdatas=Airdata.query.order_by(Airdata.airplot_id).all()
	form.plots.choices=[]
	existplot=None
	if len(airdatas)>0:
		existplot=airdatas[0].plot
		for item in airdatas:
			if item.plot!=existplot:
				form.plots.choices.append((existplot.id,existplot.plotname))
				existplot=item.plot
		form.plots.choices.append((existplot.id,existplot.plotname))
	form.plots.choices.insert(0,(-1,'全部'))
	datas=[]
	next_num=None
	prev_num=None
	pages=None
	current_page=1
	plotid=-1
	timestartstr=''
	timeendstr=''
	if request.method=='POST':
		if form.timestart.data.strip()=='':
			timestart=datetime(1990,1,1,0,0)
		else:
			timestart=datetime.strptime(form.timestart.data,'%Y-%m-%d %H:%M:%S')
		if form.timeend.data.strip()=='':
			timeend=datetime(4000,1,1,0,0)
		else:
			timeend=datetime.strptime(form.timeend.data,'%Y-%m-%d %H:%M:%S')
		page=request.args.get('page',1,type=int)
		if form.plots.data>=0:
			pagedatas=Airdata.query.filter(Airdata.airplot_id==form.plots.data,Airdata.timestamp>=timestart,Airdata.timestamp<=timeend).order_by(Airdata.timestamp).paginate(page,current_app.config['POSTS_PER_PAGE'],False)
		else:
			pagedatas=Airdata.query.filter(Airdata.timestamp>=timestart,Airdata.timestamp<=timeend).order_by(Airdata.timestamp).paginate(page,current_app.config['POSTS_PER_PAGE'],False)
		pages=pagedatas.pages
		current_page=pagedatas.page
		next_num=pagedatas.next_num if pagedatas.has_next else None
		prev_num=pagedatas.prev_num if pagedatas.has_prev else None
		datas=pagedatas.items
		plotid=form.plots.data
		timestartstr=form.timestart.data
		timeendstr=form.timeend.data
	return render_template('air/airdata.html',title='常规空气质量监测数据',datas=datas,next_num=next_num,prev_num=prev_num,form=form,plotid=plotid,timestart=timestartstr,timeend=timeendstr,pages=pages,current_page=current_page)
Beispiel #28
0
def vocdata():
	if not current_user.check_roles(['admin','air']):
		flash('您无权访问该页面')
		return redirect(url_for('main.index'))
	form=VocQueryForm()
	form.plots.choices=[(plot.id,plot.plotname) for plot in Airplot.query.order_by(Airplot.plotname).all()]
	form.voctypes.choices=[(voctype.id,voctype.vocname) for voctype in Voctype.query.order_by(Voctype.vocname).all()]
	#form.timestamps.choices=[(item.timestamp.strftime("%Y-%m-%d"),item.timestamp.strftime("%Y年%m月")) for item in Vocdata.query.group_by(Vocdata.timestamp).order_by(Vocdata.timestamp).all()]
	vocdatas=Vocdata.query.order_by(Vocdata.timestamp).all()
	form.timestamps.choices=[]
	existtime=None
	if len(vocdatas)>0:
		existtime=vocdatas[0].timestamp
		for item in vocdatas:
			if item.timestamp!=existtime:
				form.timestamps.choices.append((existtime.strftime("%Y-%m-%d"),existtime.strftime("%Y年%m月")))
				existtime=item.timestamp
		form.timestamps.choices.append((existtime.strftime("%Y-%m-%d"),existtime.strftime("%Y年%m月")))
	plots=[]	
	timestrs=[]
	voctypes=[]
	datas=[]
	if form.validate_on_submit():
		plots=Airplot.query.filter(Airplot.id.in_(form.plots.data)).all()		
		voctypes=Voctype.query.filter(Voctype.id.in_(form.voctypes.data)).all()
		times=[]
		for item in form.timestamps.data:
			times.append(datetime.strptime(item,"%Y-%m-%d"))
			timestrs.append(item)
		dataquery=Vocdata.query.filter(Vocdata.timestamp.in_(times),Vocdata.airplot_id.in_(form.plots.data),Vocdata.voctype_id.in_(form.voctypes.data)).order_by(Vocdata.timestamp,Vocdata.voctype_id)
		vocdatas=dataquery.all()
		datarow=[]
		if len(vocdatas)>0:
			datarow=[]
			voctype_id=vocdatas[0].voctype_id
			timestamp=vocdatas[0].timestamp
			for data in vocdatas:
				if voctype_id==data.voctype_id and timestamp==data.timestamp:
					datarow.append(data)
				else:
					datas.append(datarow)
					datarow=[]
					datarow.append(data)
					voctype_id=data.voctype_id
					timestamp=data.timestamp
		if len(datarow)>0:
			datas.append(datarow)
	return render_template('air/vocdata.html',title='挥发性有机物监测数据',form=form, plots=plots,datas=datas,timestrs=timestrs,voctypes=voctypes)
Beispiel #29
0
def delherbtime():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    plotid = request.form['plotid']
    time = request.form['time']
    timestamp = datetime.strptime(time, '%Y-%m-%d')
    quadratsamples = Herbsample.query.join(Herbsample.quadrat).filter(
        Herbsample.timestamp == timestamp,
        Herbquadrat.forestplot_id == plotid).all()
    for quadratsample in quadratsamples:
        for herbsample in quadratsample.herbs:
            db.session.delete(herbsample)
        db.session.delete(quadratsample)
    db.session.commit()
    return redirect(url_for('forest.herb', plotid=plotid))
Beispiel #30
0
def imgupload():
    if not current_user.check_roles(['admin', 'forest']):
        flash('您无权访问该页面')
        return redirect(url_for('main.index'))
    file = request.files['file1']
    msg = ""
    error = ""
    imgurl = ""
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(current_app.config['IMG_FOLDER'], filename)
        file.save(filepath)
        msg = "成功!文件大小为:" + str(os.path.getsize(filepath))
        imgurl = "../static/imgs/" + filename
    jsonstr = json.dumps({'error': error, 'msg': msg, 'imgurl': imgurl})
    return jsonstr