企业网站建设合同书模板,家居网站应该怎么做,网站主页排版,做外贸哪个网站比较好2017日志挖掘——处理数据、计费统计
1、读取附件中日志的内容#xff0c;找出自己学号停车场中对应的进出车次数#xff08;in/out配对的记录数#xff0c;1条in、1条out#xff0c;视为一个车次#xff0c;本日志中in/out为一一对应#xff0c;不存在缺失某条进或出记录找出自己学号停车场中对应的进出车次数in/out配对的记录数1条in、1条out视为一个车次本日志中in/out为一一对应不存在缺失某条进或出记录
2、统计自己停车场车辆累计停放秒即某个车牌车辆驶出时间-车辆驶入时间本此停放秒数统计自己车场全部车牌的累计
在日志挖掘实验基础上针对车辆进出进行计费。
计费规则如下
1、进场后在30分钟内出场的车辆免收费
2、停放在2小时内含2小时收费10元从第三小时起每小时2元。
3、不封顶。
public class CountPark {static MapString,Integer profitnew HashMap();static MapString,String mapnew HashMap();static long cnt0,time0;static SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);static SimpleDateFormat sdf2 new SimpleDateFormat(yyyy-MM);public static ListString readTxt(String fileName){ListString listnew ArrayList();try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */System.out.println(fileName);File filename new File(fileName); // 要读取以上路径的input。txt文件InputStreamReader reader new InputStreamReader(new FileInputStream(filename),gbk); // 建立一个输入流对象readerBufferedReader br new BufferedReader(reader); // 建立一个对象它把文件内容转成计算机能读懂的语言String line ;line br.readLine();while (line ! null) {String[] templine.split(,);if(temp[1].equals(2018250)){if(map.containsKey(temp[2])){long cursdf.parse(temp[0]).getTime();int cost0;String monthsdf2.format(sdf.parse(temp[0]));long presdf.parse(map.get(temp[2])).getTime();double curTime((double) (cur-pre))/1000;//秒if(curTime1800)//大于半小时{cost10;//收10元double hour Math.ceil(curTime/(60*60));//小时if(hour2)//两小时以上cost(hour-2)*2;}profit.put(month,profit.getOrDefault(month,0)cost);//记录map.remove(temp[2]);}elsemap.put(temp[2],temp[0]);cnt;}line br.readLine();}} catch (Exception e) {e.printStackTrace();}return list;}public static void main(String[] args) {long cSystem.currentTimeMillis();ListString listreadTxt(cars2.txt);System.out.println(运行时间秒:(double)(System.currentTimeMillis()-c)/1000秒);for(String s:profit.keySet())System.out.println(s:profit.get(s));}
}
日志挖掘——并行改造
1、读取文件并行化数据分割
具体做法针对之前一个大日志文件根据时间例如按照日期进行切割切割为多个小文件。读取时每天的数据分别读取
2、处理并行化任务分割
具体做法针对每个日期分别进行各种扫描和统计对于跨日期的数据存放在公用地方到时再配对处理
public class CountPark2 {static MapString,ArrayListString profitnew HashMap();static MapString,String mapnew HashMap();static long cnt0,time0;static SimpleDateFormat formatter new SimpleDateFormat(HH:mm:ss.SSS);static SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);static SimpleDateFormat sdf2 new SimpleDateFormat(yyyy-MM);public static void readTxt(String fileName){ListString listnew ArrayList();try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File filename new File(fileName); // 要读取以上路径的input。txt文件InputStreamReader reader new InputStreamReader(new FileInputStream(filename),gbk); // 建立一个输入流对象readerBufferedReader br new BufferedReader(reader); // 建立一个对象它把文件内容转成计算机能读懂的语言String line ;line br.readLine();while (line ! null) {String[] templine.split(,);if(temp[1].equals(2018250)){long cursdf.parse(temp[0]).getTime(); String monthsdf2.format(sdf.parse(temp[0]));if(!profit.containsKey(month)) profit.put(month,new ArrayList());profit.get(month).add(line);}line br.readLine();} }catch (Exception e) {e.printStackTrace();}}public static void writeTxt(String content,String filename){try {File writename new File(src/logminning/reso/filename); // 相对路径如果没有则要建立一个新的output.txt文件writename.createNewFile(); // 创建新文件BufferedWriter out new BufferedWriter(new FileWriter(writename));out.write(content); // \r\n即为换行out.flush(); // 把缓存区内容压入文件out.close(); // 最后记得关闭文件} catch (Exception e) {e.printStackTrace();}}public void handle(){readTxt(cars2.txt);for(String c:profit.keySet()){StringBuilder stringBuildernew StringBuilder();for(String t:profit.get(c))stringBuilder.append(t).append(\r\n);writeTxt(stringBuilder.toString(),c);}}public static void main(String[] args) {ConcurrentHashMapString, PriorityBlockingQueueLong concurrentHashMapnew ConcurrentHashMap();BlockingQueueString blockingQueuenew LinkedBlockingQueue();ExecutorService executorService Executors.newFixedThreadPool(8);CountDownLatch countDownLatchnew CountDownLatch(6);System.out.println(Start ReadFile:formatter.format(new Date()));for(int i1;i6;i){executorService.execute(new ReadFileThread(concurrentHashMap,src/logminning/reso/2020-0String.valueOf(i).txt,countDownLatch));}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}System.out.println(End ReadFile:formatter.format(new Date()));
/* int used0;for(String c:concurrentHashMap.keySet()){if(concurrentHashMap.get(c).size()2) continue;System.out.println(c:concurrentHashMap.get(c).size());usedconcurrentHashMap.get(c).size();}System.out.println(used);*/Res resnew Res();countDownLatchnew CountDownLatch(6);for(int i0;i26;i5){executorService.execute(new handler(concurrentHashMap,countDownLatch,i,res));}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}System.out.println(End Process:formatter.format(new Date()));System.out.println(res.getTar():res.getUsed());executorService.shutdown();}
}
public class handler implements Runnable{CountDownLatch countDownLatch;ConcurrentHashMapString, PriorityBlockingQueueLong concurrentHashMap;int s;Res res;public handler(ConcurrentHashMapString, PriorityBlockingQueueLong concurrentHashMap,CountDownLatch countDownLatch,int s,Res res) {this.ss;this.resres;this.countDownLatchcountDownLatch;this.concurrentHashMap concurrentHashMap;}Overridepublic void run() {try {for(String c:concurrentHashMap.keySet() ){int curc.charAt(1)-A;if(curscurs5){PriorityBlockingQueueLong priorityQueueconcurrentHashMap.get(c);while (priorityQueue.size()0){long c1priorityQueue.take(),c2priorityQueue.take();res.add((c2-c1)/1000);}}}} catch (Exception e) {e.printStackTrace();}countDownLatch.countDown();}
}
public class ReadFileThread implements Runnable {private ConcurrentHashMapString, PriorityBlockingQueueLong concurrentHashMap;private String fileName;CountDownLatch countDownLatch;SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);public ReadFileThread(ConcurrentHashMapString, PriorityBlockingQueueLong concurrentHashMap, String filename, CountDownLatch countDownLatch) {this.concurrentHashMap concurrentHashMap;this.fileName filename;this.countDownLatchcountDownLatch;}Overridepublic void run() {try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File filename new File(fileName); // 要读取以上路径的input。txt文件InputStreamReader reader new InputStreamReader(new FileInputStream(filename),UTF-8); // 建立一个输入流对象readerBufferedReader br new BufferedReader(reader); // 建立一个对象它把文件内容转成计算机能读懂的语言String line ;line br.readLine();while (line ! null) {String[] templine.split(,);if(!concurrentHashMap.containsKey(temp[2]))concurrentHashMap.put(temp[2],new PriorityBlockingQueue());synchronized (this){long cursdf.parse(temp[0]).getTime(); concurrentHashMap.get(temp[2]).add(cur);}line br.readLine();}} catch (Exception e) {e.printStackTrace();}countDownLatch.countDown();}
}
public class Res {private long tar 0;private int used0;public long getTar() {return tar;}public int getUsed() {return used;}public synchronized void add(long c){tarc;used;}
}