三、农机运营分析(按月分析)
这里的运营是指除了停运和停车熄火之外的其他状态,包括行驶、停车检查、田间作业等状态。运营时间和运营里程反映农机的使用率以及农机手的工作强度。
5个月农机作业轨迹数量的部分展示(统计10月份每天的作业车辆和轨迹个数)
val oct_stat = sql(" select distinct to_date(gps_time) as gps_t, count(gps_time) as num_trajectory ,count(distinct vme_id) as num_car, avg(speed) avg_speed from trajectory where month(gps_time)=10 group by to_date(gps_time) order by gps_t")
//保存数据到本地
oct_stat.repartition(1).write.mode("overwrite").format("csv").save("file:/home/hadoop/mydata/oct_stat")
1.运营时间与距离分析
10月日均运营时间分析(日均运营时间是指该日运营农机的运营时间总和与当日运营出租车的总和之比)
val oct_operation= sql(" select a.gps_t, day(a.gps_t) as day,a.num_trajectory, a.num_car, a.avg_speed, a.num_trajectory*2/a.num_car/3600 as avg_day_operation_time, a.avg_speed* a.num_trajectory*2/a.num_car/1000 as avg_day_operation_distance from (select distinct to_date(gps_time) as gps_t, count(gps_time) as num_trajectory ,count(distinct vme_id) as num_car, avg(speed) avg_speed from trajectory where month(gps_time)=10 group by to_date(gps_time) order by gps_t) as a")
//保存数据到本地
oct_operation.repartition(1).write.mode("overwrite").format("csv").save("file:/home/hadoop/mydata/oct_operation")