系统简介
共享单车在城市出行中扮演着越来越重要的角色,与此同时,共享单车运营商需要有效地管理和分析大量的数据以提升用户体验和运营效率。本文提出了基于大数据技术的共享单车数据分析与辅助管理系统,以协助运营商更好地管理共享单车。
该系统利用Python语言、MySQL数据库,Flask框架,结合目前流行的 B/S架构,将共享单车数据分析与辅助管理系统的各个方面都集中到数据库中,以便于用户的需要。该系统在确保系统稳定的前提下,能够实现多功能模块的设计和应用。该系统由管理员功能模块和用户功能模块组成。不同角色的准入制度是有严格区别的。各功能模块的设计也便于以后的系统升级和维护。该系统采用了软件组件化、精化体系结构、分离逻辑和数据等方法。
关键字:大数据;共享单车;数据分析;辅助管理系统;Python语言;MySQL
2 系统设计
4.1 功能模块设计
对本系统进行全面的系统功能的分析,可以得出基于Python共享单车数据分析与辅助管理系统的功能模块图,如图4-1所示。

图4-1 系统功能模块图
4.2 搭建Hadoop集群
Hadoop是一个分布式系统框架,同时对硬件要求不高。因此采用普通的PC电脑就可以搭建一个大规模的集群,实现分布式程序的运行。本文就是采用了4台家用PC搭建了一个计算集群,在集群上对数据进行分析处理。集群采用B/S架构,可在Web浏览器上访问集群,进行集群相关信息的查看、数据的下载、任务执行状态的查看。对集群的配置则通过Xshell远程连接实现。搭建集群所使用的硬件配置以及软件配置如下表4-1、4-2所示。
4.2.1 Hadoop配置文件
coresite.xml文件配置代码
fs.defaultFS
hdfs://master:8020//默认HDFS端口,用于主从节点通信
hadoop.tmp.dir
/var/log/hadoop/tmp//存放Hadoop文件系统依赖的基本配置
mapred-site.xml文件配置代码
mapreduce.framework.name
yarn//用于执行MapReduce作业的运行时框架
mapreduce.jobhistory.address
master:10020//指定历史服务器的地址和端口
mapreduce.jobhistory.webapp.address
master:19888//历史服务器的web地址
yarn-site.xml文件配置代码
hdfs-site.xml文件配置代码
dfs.namenode.name.dir
file:///data/hadoop/hdfs/name
// NameNode的多目录配置
dfs.datanode.data.dir
file:///data/hadoop/hdfs/data
dfs.namenode.secondary.http-address
master:50090
// secondary NameNode 的web访问地址
dfs.replication
3
//数据块副本备份个数设置
第三章 效果图与代码


注册接口
@main_bp.route(“/python05c7298x/changdixinxi/register”, methods=[‘POST’])
def python05c7298x_changdixinxi_register():
if request.method == ‘POST’:
msg = {‘code’: normal_code, ‘message’: ‘success’, ‘data’: [{}]}
req_dict = session.get(“req_dict”)
error = changdixinxi.createbyreq(changdixinxi, changdixinxi, req_dict)
if error!=None:
msg[‘code’] = crud_error_code
msg[‘msg’] = “注册用户已存在”
return jsonify(msg)

登录接口
@main_bp.route(“/python05c7298x/aboutus/login”, methods=[‘GET’,‘POST’])
def python05c7298x_aboutus_login():
if request.method == ‘GET’ or request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
req_model = session.get(“req_dict”)
try:
del req_model[‘role’]
except:
pass
datas = aboutus.getbyparams(aboutus, aboutus, req_model)
if not datas:
msg[‘code’] = password_error_code
msg[‘msg’]=‘密码错误或用户不存在’
return jsonify(msg)
req_dict[‘id’] = datas[0].get(‘id’)
try:
del req_dict[‘mima’]
except:
pass
return Auth.authenticate(Auth, aboutus, req_dict)

保存接口(后端)
@main_bp.route(“/python05c7298x/danchexinxi/save”, methods=[‘POST’])
def python05c7298x_danchexinxi_save():
‘’’
‘’’
if request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
if danchexinxi.count(danchexinxi, danchexinxi, {“danchebianhao”:req_dict[“danchebianhao”]})>0:
msg[‘code’] = crud_error_code
msg[‘msg’] = “单车编号已存在”
return jsonify(msg)
for key in req_dict:
if req_dict[key] == ‘’:
req_dict[key] = None
error= danchexinxi.createbyreq(danchexinxi, danchexinxi, req_dict)
if error!=None:
msg[‘code’] = crud_error_code
msg[‘msg’] = error
return jsonify(msg)

保存接口
@main_bp.route(“/python05c7298x/changdixinxi/save”, methods=[‘POST’])
def python05c7298x_changdixinxi_save():
‘’’
‘’’
if request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
if changdixinxi.count(changdixinxi, changdixinxi, {“changdibianhao”:req_dict[“changdibianhao”]})>0:
msg[‘code’] = crud_error_code
msg[‘msg’] = “场地编号已存在”
return jsonify(msg)
for key in req_dict:
if req_dict[key] == ‘’:
req_dict[key] = None
error= changdixinxi.createbyreq(changdixinxi, changdixinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)
)

#__authSeparate__此属性为真,params添加userid,只查询个人数据
try:
authSeparate = model.sort
except:
authSeparate = None
if authSeparate and authSeparate!=“否”:
if “userid” in self.getallcolumn(model,model) and session.get(“params”)!=None:
params[“userid”]=session.get(“params”).get(“id”)
if “userid” not in self.getallcolumn(model,model) and “userid” in params.keys():
del params[“userid”]
if sort!=None or sort!=None:
if sort==None:
sort=sort
if order == ‘desc’:
#del params[‘order’]
# 传参判断,需要逆序
# datas= model.query.filter_by(
# **params
# ).filter(or_clauses).order_by(desc(text(sort))).paginate(
# page=int(page),
# per_page=int(limit),
# error_out=False
# )
datas= eval('''model.query.filter_by(
**params
){}.filter(or_clauses).order_by(desc(text(sort))).paginate(
page=int(page),
per_page=int(limit),
error_out=False
)'''.format(contain_str))



添加接口
@main_bp.route(“/python05c7298x/changdixinxi/add”, methods=[‘POST’])
def python05c7298x_changdixinxi_add():
‘’’
‘’’
if request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
if changdixinxi.count(changdixinxi, changdixinxi, {“changdibianhao”:req_dict[“changdibianhao”]})>0:
msg[‘code’] = crud_error_code
msg[‘msg’] = “场地编号已存在”
return jsonify(msg)
try:
foreEndListAuth=changdixinxi.foreEndListAuth
except:
foreEndListAuth=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=session.get("tablename")
if tablename!="users":
req_dict['userid']=session.get("params").get("id")
error= changdixinxi.createbyreq(changdixinxi, changdixinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)

添加接口
@main_bp.route(“/python05c7298x/danchexinxi/add”, methods=[‘POST’])
def python05c7298x_danchexinxi_add():
‘’’
‘’’
if request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
if danchexinxi.count(danchexinxi, danchexinxi, {“danchebianhao”:req_dict[“danchebianhao”]})>0:
msg[‘code’] = crud_error_code
msg[‘msg’] = “单车编号已存在”
return jsonify(msg)
try:
foreEndListAuth=danchexinxi.foreEndListAuth
except:
foreEndListAuth=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=session.get("tablename")
if tablename!="users":
req_dict['userid']=session.get("params").get("id")
error= danchexinxi.createbyreq(danchexinxi, danchexinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)

label=“归还状态”>
{{scope.row.guihaizhuangtai}}
{{scope.row.qixingshijian}}
{{scope.row.zhanghao}}
{{scope.row.xingming}}

@main_bp.route(“/python05c7298x/danchexinxi/add”, methods=[‘POST’])
def python05c7298x_danchexinxi_add():
‘’’
‘’’
if request.method == ‘POST’:
msg = {“code”: normal_code, “msg”: “success”, “data”: {}}
req_dict = session.get(“req_dict”)
if danchexinxi.count(danchexinxi, danchexinxi, {“danchebianhao”:req_dict[“danchebianhao”]})>0:
msg[‘code’] = crud_error_code
msg[‘msg’] = “单车编号已存在”
return jsonify(msg)
try:
foreEndListAuth=danchexinxi.foreEndListAuth
except:
foreEndListAuth=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=session.get("tablename")
if tablename!="users":
req_dict['userid']=session.get("params").get("id")
error= danchexinxi.createbyreq(danchexinxi, danchexinxi, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return jsonify(msg)




950

被折叠的 条评论
为什么被折叠?



