不能說のsecret 7

一段混沌時期過去了,有些無奈,有些瘋狂,有些歡喜,有些迷失,總之,它是過去了。

之前的一段時間給新來的博士老師查資料,關於列車聯網的,什麼CTCS3,ETCS,CTC,TDCS,TDMS,TDCS,RSM-R等一系列新名詞,還好也算努力的去做然後交工了,如果有這方面需要的,可以提供一些資料(只保證近期不會刪除)。

最近在看了老師給的一些資料,主要是hadoop權威指南,對這個平臺,包括HDFS和MapReduce有了一些淺顯的理解,我知道開始都是比較困難的,慢慢的堅持吧。俗話說好記憶不如爛筆頭,看的同時也記錄了一些比較重要又不是很容易理解的知識點,防止過後就忘(雖然這樣保質期也不長,o(︶︿︶)o 唉)。

說好的hadoop平臺被一拖再拖,實在是有點心有愧疚,前天在實驗室3臺電腦組成的集羣上編寫了第一個可以被認爲是mapreduce程序的小應用,在網上下載了一個雲層天氣數據集,120個文件作爲輸入,通過程序查看單個站點十幾年的天氣變化情況,幾分鐘處理了幾億條數據還是令我這小菜鳥蠻吃驚的,程序雖然比較簡單,類似與wordcount,不過麻雀雖小,五臟還是不少的,至少練習了MapReduce程序的開發過程,這個應該算是比較基礎的了,繼續熟悉才能深入吧。

附上這個簡單實現:

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

/**
 * 記錄同一觀測站的天氣狀況出現的次數
 * key=年月+天氣狀況 value=次數
 *      Ppt        precipitation            ww= 50-75,77,79,80-99              .
        D          drizzle                    50-59                            .
        R          rain                       60-69                            .
        S          snow                       70-75,77,79                      .
        Ts         thunderstorm,shower        80-99                            .
 * @author ubuntu
 * 2012.8.11
 */
public class WeatherCount {
	public static class WeatherCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
		private final static IntWritable one = new IntWritable(1);
		
		protected void map(LongWritable key, Text value, Context context)
				throws IOException, InterruptedException {
			String line = value.toString();//讀取一行
			String time = line.substring(0,4);//年月
			int station = Integer.parseInt(line.substring(19,24).trim());//站臺
			if(station==71906){
				String ww = line.substring(25,27);//天氣指標
				int weatherIndex = 0;//天氣指數
				String weather = null;
				if(!ww.equals("-1")){//-1代表數據丟失
					weatherIndex = Integer.parseInt(ww.trim());
					if(weatherIndex>=50&&weatherIndex<=59)
						weather = "drizzle";
					else if(weatherIndex>=60&&weatherIndex<=69)
						weather = "rain";
					else if((weatherIndex>=70&&weatherIndex<=75)||weatherIndex==77||weatherIndex==79)
						weather = "snow";
					else if(weatherIndex>=80&&weatherIndex<=99)
						weather = "thunderstorm";
					if(weather!=null){
						context.write(new Text(time+weather), one);
					}
				}
			}
		}
	}
	public static class WeatherCountReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

		protected void reduce(Text key, Iterable<IntWritable> values,
				Context context)
				throws IOException, InterruptedException {
			int sum = 0;
			for(IntWritable value : values){
				sum += value.get();
			}
			context.write(key, new IntWritable(sum));
		}
	}
	public static void main(String[] args) throws Exception{
		Configuration conf = new Configuration();
		String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
		if(otherArgs.length!=2){
			System.err.println("Usage:WeatherCount <input path> <output path>");
			System.exit(-1);
		}
		
		Job job = new Job(conf,"weather count");
		job.setJarByClass(WeatherCount.class);
		FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
		FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
		job.setMapperClass(WeatherCountMapper.class);
		job.setCombinerClass(WeatherCountReducer.class);
		job.setReducerClass(WeatherCountReducer.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		
		System.exit(job.waitForCompletion(true)?0:1);
	}

}


今天把系科系統(CxServer)給搭上了,雖然是好久之前老師讓改的,但是還是覺得這個系統比較難懂,用wt庫加C++編寫的網站,實在讓我頭大,加上不是很熟悉的Linux服務器……不過,由於第一次部署這個系統時比較用心,克服了許多困難,上論壇,搜網頁,解決了很多問題,(包括程序自己的!),這次搭的時候還算比較順利,下午放到了學校的服務器上,加了url轉發,外網算是可以登錄了,對於這個創新基金管理系統,如果遇到了搭建問題,也可以一起討論。

至於感情,我想,我是覺得好寂寞了……前兩天打球時遇到了她,話說人家現在過的很好,我真是屌絲,就不能也信守承諾,過自己的生活麼!?有句話說的好,想要忘記就要“不要見,不要賤”。

人生總是要遇到無可知的路途,暫時的迷失不要緊,大方向不能丟,時常讓自己快樂,瘋狂,忘我,青春就是用來還債的。

決定去健身了,hold不住了。如果你是宅,請記得有個好身體。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章