2 Star 0 Fork 0

HuaweiCloudDeveloper / huaweicloud-solution-driving-behavior-analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

[TOC]

解决方案介绍

该解决方案基于华为云数据湖探索 DLI Spark作业构建,通过对驾驶人驾驶行为的分析,帮助您快速的进行车辆数据管理与分析。DLI 是一个强大的大数据处理平台,它可以帮助您轻松地管理和分析车辆数据。通过使用标准 SQL 和 Spark 程序,您可以在云上进行多数据源的联合计算分析,从而挖掘和探索数据价值。适用于以下场景: 1、智能驾驶: 通过分析车辆数据,可以提供有关驾驶行为的深入见解,以改善驾驶体验、提高道路安全,并优化交通流量。 2、自动驾驶: 通过分析车辆数据,可以训练自动驾驶模型,以提高自动驾驶的准确性和效率。 3、安全预警: 通过分析车辆数据,可以预测和识别潜在的安全问题,提前采取措施,防止事故发生。 4、用户行为分析: 通过分析车辆数据,可以了解用户的驾驶习惯和行为,以提供更好的服务和产品。

解决方案实践详情页面:https://www.huaweicloud.com/solution/implementations/driving-behavior-analysis.html

架构图

方案架构

架构描述

该解决方案会部署如下资源:

  1. 创建一台云数据库 RDS for MySQL实例,用于存储统计的驾驶行为数据。

  2. 创建数据湖探索 DLI增强型跨源队列,并创建SQL作业,用于分析和处理驾驶行为数据。

  3. 创建数据湖探索 DLI跨源认证,用于DLI访问RDS for MySQL同步写入驾驶行为数据。

  4. 创建两个对象存储服务 OBS桶,一个用于用户上传驾驶行为数据,另一个用于上传连接RDS的SQL文件。

  5. 使用函数工作流 FunctionGraph创建两个函数,一个用于自动创建DLI 数据库表并将用户上传的驾驶行为数据自动写入,另一个用于自动在RDS创建数据表模板。

组织结构

huaweicloud-solution-driving-behavior-analysis
├──driving-behavior-analysis.tf.json -- 资源编排模板
├── functiongraph
    ├──  driving_behavior_analysis_dli.py -- 函数文件(DLI)
    ├──  driving_behavior_analysis_rds.py -- 函数文件(RDS)
    ├──  driving_behavior_analysis_unzip -- 函数解压文件

开始使用

通过对象存储服务 OBS预测

1、查看OBS桶。在控制台单击“服务列表”,选择“对象存储服务 OBS”,单击进入OBS页面。该桶将作为用户上传驾驶行为数据文件的存储桶。

图1 OBS桶(DLI) 查看OBS桶

2、查看OBS桶。在控制台单击“服务列表”,选择“对象存储服务 OBS”,单击进入OBS页面。该桶将作为用户上传DLI连接RDS数据库SQL文件的存储桶。

图2 OBS桶(RDS)

查看OBS桶

3、体验Demo样例。获取Demo数据样例文件,上传至步骤1中的OBS桶中,即可触发函数工作流自动解压文件,创建DLI数据库表并主动写入上传的数据,生成DLI连接RDS的SQL文件并自动在MySQL中创建结果表。(定制化开发请获取开源代码参考代码注释,参照函数工作流FunctionGraph定制化开发修改代码并重新部署,上传驾驶行为数据zip或tar压缩文件至OBS桶即可自动创建DLI数据库表并写入数据。)

须知:
1、本方案仅支持上传压缩包,其他文件会导致本方案不能正常使用。
2、暂不支持OBS上传KMS加密的数据文件。
文件解压
压缩包的类型只支持zip和tar,压缩包文件名及其路径不能含中文。
单个压缩包解压后文件最大不超过200MB。

图3 上传驾驶行为数据文件压缩包

上传驾驶行为数据文件压缩包

图4 自动解压数据文件至当前目录下

上传驾驶行为数据文件压缩包

4、获取DLI连接RDS的SQL文件。查看步骤2中的OBS桶,依次单击“对象”“下载”下载文件到本地,使用记事本打开,复制文件内容。

图5 查看rds结果桶

查看rds结果桶

图6 使用记事本打开

使用记事本打开

5、创建同步数据表。在控制台单击“服务列表”,选择“数据湖探索 DLI”单击左侧导航栏“SQL编辑器”,代码框上部执行引擎选择“spark”,队列及数据库选择本方案创建的队列及数据库,粘贴步骤5复制的SQL文件内容,选中如图所示的SQL语句,单击“执行”创建与RDS MySQL 同步的数据表。刷新页面,即可查看数据表的创建结果。

图7 创建同步数据表

创建同步数据表

图8 查看执行结果

查看执行结果

6、插入数据。选中如图所示的SQL语句,单击“执行”即可插入数据到event_records表,并同步写入到RDS数据表中。

图9 插入数据

插入数据

7、查看SQL作业执行状态。依次单击左侧导航栏“作业管理”“SQL作业”查看SQL作业的执行状态。(按Demo案例,如果运行时长超过2分钟状态未更新,请刷新页面查看。)

图10 查看SQL作业执行状态

查看SQL作业执行状态

8、进入云数据库RDS控制台,选择本方案创建的RDS实例,单击“登录”跳转至实例管理服务DAS 实例登录界面。

图11 云数据库RDS控制台

云数据库RDS控制台

9、登录实例。输入密码,勾选记住密码,开启定时采集及SQL执行记录,单击“测试连接”登录实例。

图12 登录实例

登录实例

10、查询同步到数据表的数据。单击“SQL查询”,执行如下SQL语句,即可查询到经过speak SQL作业处理与DLI同步的表数据。

图13 进入SQL查询

进入SQL查询

图14 执行SQL查询语句

执行SQL查询语句

11、执行DLI Sprak作业SQL查询执行SQL查询。在控制台单击“服务列表”,选择“数据湖探索 DLI”单击左侧导航栏“SQL编辑器”,代码框上部执行引擎选择“spark”队列及数据库选择本方案创建的队列及数据库,单击“执行”执行以下SQL语句,对所有司机在某段时间的异常告警事件进行统计。更多SQL语法使用请参考Spark SQL语法概览

图15 执行SQL查询

进入SQL查询

select
  driverID,
  carNumber,
  sum(isRapidlySpeedup) as rapidlySpeedupTimes,
  sum(isRapidlySlowdown) as rapidlySlowdownTimes,
  sum(isNeutralSlide) as neutralSlideTimes,
  sum(neutralSlideTime) as neutralSlideTimeTotal,
  sum(isOverspeed) as overspeedTimes,
  sum(overspeedTime) as overspeedTimeTotal,
  sum(isFatigueDriving) as fatigueDrivingTimes,
  sum(isHthrottleStop) as hthrottleStopTimes,
  sum(isOilLeak) as oilLeakTimes
from
  event_records
where
  time >= "2017-01-01 00:00:00"
  and time <= "2017-02-01 00:00:00"
group by
  driverID,
  carNumber
order by
  rapidlySpeedupTimes desc,
  rapidlySlowdownTimes desc,
  neutralSlideTimes desc,
  neutralSlideTimeTotal desc,
  overspeedTimes desc,
  overspeedTimeTotal desc,
  fatigueDrivingTimes desc,
  hthrottleStopTimes desc,
  oilLeakTimes desc

12、查询结果。在查询结果中,单击 ,实现“结果图形化”。进入图形化界面后“图形类型”选择“柱状图”“X轴”选择“driverID”“Y轴”选择“rapidlySpeedupTimes”“结果数目”选择“10”展示结果如下:

图16 查看结果

查看结果

图17 结果图形化

结果图形化

SQL语句示例:

1、查询某个司机在某个时间段的详细记录:
select
  *
from
  event_records
where
  driverID = "panxian1000005"
  and time >= "2017-01-01 00:00:00"
  and time <= "2017-02-01 00:00:00"

2、查看订单信息:
select
  *
from
  order_records
where
  orderNumber = "2017013013584419488"
order by
  time desc

3、根据司机和发车时间信息查询司机的详细行驶特点:
select
  driverID,
  carNumber,
  latitude,
  longitude,
  siteName,
  time
from
  detail_records
where
  driverID = "panxian1000005"
  and time > "2017-01-30 16:00:00"
  and siteName IS NOT NULL
order by  time desc
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

该解决方案基于华为云数据湖探索 DLI构建,帮助您快速的进行车辆数据管理与分析。 展开 收起
Python
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/HuaweiCloudDeveloper/huaweicloud-solution-driving-behavior-analysis.git
git@gitee.com:HuaweiCloudDeveloper/huaweicloud-solution-driving-behavior-analysis.git
HuaweiCloudDeveloper
huaweicloud-solution-driving-behavior-analysis
huaweicloud-solution-driving-behavior-analysis
master-dev

搜索帮助