79 Star 1 Fork 2

lx/tit-bd-2023

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
7\8 6.27 KB
一键复制 编辑 原始数据 按行查看 历史
罗涛 提交于 2024-08-29 10:12 . add 7\8.
<%@page import="com.ReadFileUtil" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<%@page import="org.apache.hadoop.fs.FSDataInputStream" %>
<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>Insert title here</title>
<List<String> ll =
ReadFileUtil.ReadFromHDFS("hdfs://master:9000/out/view2/part-00000");%>
   <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
</head>
<body>
<div class="chart" id="main" style="width: 900px;height:400px;"></div>
<script type="text/javascript">
   // 基于准备好的dom,初始化echarts实例
   var myChart = echarts.init(document.getElementById('main'));
   // 指定图表的配置项和数据
   var option = {
       title: {
           text: '最大代理人TOP20'
       },
       tooltip: {},
       legend: {
           data: ['票数']
       },
       xAxis: {
           data: ["<%=ll.get(0)%>"<%for(int i=1;i<40;i++){
                   if(i%2==0){
                       %>, "<%=ll.get(i)%>"
               <%
                   }
               }
               %>]
       },
       yAxis: {},
       series: [{
           name: '票数',
           type: 'bar',
           data: [<%=ll.get(1)%>
               <%for(int i=2;i<40;i++){
                   if(i%2==1){
                   %>, <%=ll.get(i)%>
               <%
                   }
               }
               %>]
       }]
   };
   // 使用刚指定的配置项和数据显示图表。
   myChart.setOption(option);
</script>
<h2 color="red"><a href="index.jsp">返回</a></h2>
</body>
package com;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;
public class MoneyByDay {
public static void main(String[] args) throws Exception {
try {
// spark://master:7077
// yarn-client
SparkConf conf=new SparkConf().setAppName("TicketsCount3").setMaster("local[3]");
JavaSparkContext sc = new JavaSparkContext(conf);
/**
* 数据初步清理,主要是过滤出各个机场个总票数
*/
JavaRDD<String> lines = sc.textFile("hdfs://master:9000/user/data/region.csv", 1);
lines = lines.filter(line ->
line.split(",")[1].substring(0, 1).equals("C") &&
line.split(",")[0].equals("21")
);
JavaPairRDD<String, Integer> pair = lines.mapToPair(line ->
new Tuple2<>(line.split(",")[1], Integer.parseInt(line.split(",")[4]))
);
JavaPairRDD<String, Integer> counts = pair.reduceByKey((v1, v2) -> (v1 + v2));
/**
* 数据二次清理,进行排序
*/
JavaPairRDD<Integer, String> counts_r = counts.mapToPair(t -> new Tuple2<>(t._2, t._1));
JavaPairRDD<Integer, String> sorted_counts_r = counts_r.sortByKey(false);
JavaPairRDD<String, Integer> sortedcounts = sorted_counts_r.mapToPair(t -> new Tuple2<>(t._2, t._1));
sortedcounts.foreach(t -> {
System.out.println(t._1 + "appears " + t._2 + " $.");
});
sortedcounts.saveAsTextFile("hdfs://master:9000/out/view3");
sc.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
}
<%@page import="com.ReadFileUtil" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<%@page import="org.apache.hadoop.fs.FSDataInputStream" %>
<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>Insert title here</title>
<List<String> ll =
ReadFileUtil.ReadFromHDFS("hdfs://master:9000/out/view3/part-00000");%>
   <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
</head>
<body>
<div class="chart" id="main" style="width: 900px;height:400px;"></div>
<script type="text/javascript">
   // 基于准备好的dom,初始化echarts实例
   var myChart = echarts.init(document.getElementById('main'));
   // 指定图表的配置项和数据
   var option = {
       title: {
           text: '第21天各机场销售额的Top20'
       },
       tooltip: {},
       legend: {
           data: ['销售额']
       },
       xAxis: {
           data: ["<%=ll.get(0)%>"<%for(int i=1;i<40;i++){
                   if(i%2==0){
                       %>, "<%=ll.get(i)%>"
               <%
                   }
               }
               %>]
       },
       yAxis: {},
       series: [{
           name: '销售额',
           type: 'bar',
           data: [<%=ll.get(1)%>
               <%for(int i=2;i<40;i++){
                   if(i%2==1){
                   %>, <%=ll.get(i)%>
               <%
                   }
               }
               %>]
       }]
   };
   // 使用刚指定的配置项和数据显示图表。
   myChart.setOption(option);
</script>
<h2 color="red"><a href="index.jsp">返回</a></h2>
</body>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/376473984/tit-bd-2023.git
git@gitee.com:376473984/tit-bd-2023.git
376473984
tit-bd-2023
tit-bd-2023
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385