Simple Mobile Internet Data entry case

Source: Internet
Author: User

Through the analysis of mobile Internet data, we understand the behavior of mobile terminals on the Internet and the development of various applications on the Internet.

This includes statistics on the usage of different applications, statistics of daily active users (DAU) and monthly active users (MAU) on mobile internet, and analysis of upstream downlink traffic statistics in different applications.

To simplify the analysis of mobile Internet data, I'm here to be an introduction.

Suppose that the mobile Internet Data is as follows

Nodeid that is, the base station ID information CI is the cell identity information IMEI that the international mobile phone device identification Code app is the application name time is the access times uplinkbytes that is the number of bytes upstream downlinkbytes that is the number of bytes downstream

1,1,460028714280218,360,2015-05-01,7,1116
1,2,460028714280219,qq,2015-05-02,8,121
1,3,460028714280220,yy,2015-05-03,9,122
1,4,460028714280221,360,2015-05-04,10,119
2,1,460028714280222,yy,2015-05-05,5,1119
2,2,460028714280223,360,2015-05-01,12,121
2,3,460028714280224,qq,2015-05-02,13,122
3,1,460028714280225,qq,2015-05-03,1,1117
3,2,460028714280226,qq,2015-05-04,9,1118
3,3,460028714280227,qq,2015-05-05,10,120
1,1,460028714280218,360,2015-06-01,11,1118
1,2,460028714280219,qq,2015-06-02,2,1119
1,3,460028714280220,yy,2015-06-03,9,1120
1,4,460028714280221,360,2015-06-04,10,119
2,1,460028714280222,yy,2015-06-05,11,1118
2,2,460028714280223,360,2015-06-01,11,121
2,3,460028714280224,qq,2015-06-02,4,1119
3,1,460028714280225,qq,2015-06-03,17,119
3,2,460028714280226,qq,2015-06-04,19,1119
3,3,460028714280227,qq,2015-06-05,20,121

New Mobileinternet

Data source, placed in the directory under the project root directory

Code:

Package Cn.spark.study.core

Import org.apache.spark.SparkConf
Import Org.apache.spark.SparkContext
Import org.apache.log4j. {Level,logger}

Object Mobileinternet {
def main (args:array[string]) {
Val conf = new sparkconf ()
. Setappname ("WordCount")
. Setmaster ("local");
Val sc = new Sparkcontext (conf)

To remove too much log information
Logger.getlogger ("Org.apache.spark"). SetLevel (Level.warn)
Logger.getlogger ("Org.apache.spark,sql"). SetLevel (Level.warn)
Logger.getlogger ("Org.apache.hadoop.hive.ql"). SetLevel (Level.warn)


/*
*, one, mobile Internet data field model and other variables definition
*/
//Define the field list of the current mobile Internet Data
Val fields = List ("NodeID", "CI", "IMEI", "APP", " Time "," Uplinkbytes "," Downlinkbytes ")

//To avoid transferring the fields information in each task task, you can broadcast
val bcfields = Sc.broadcast ( Fields)

/*nodeid is the base station ID information CI is the cell identity information IMEI that the international mobile phone device identification Code app is the application name time is the access times uplinkbytes that is the number of bytes upstream downlinkbytes that is the number of bytes downstream
1,1,460028714280218,360,2015-05-01,7,1116
1,2,460028714280219,qq,2015-05-02,8,121
1,3,460028714280220,yy , 2015-05-03,9,122
1,4,460028714280221,360,2015-05-04,10,119
2,1,460028714280222,yy,2015-05-05,5,1119
2,2,460028714280223,360,2015-05-01,12,121
2,3,460028714280224,qq,2015-05-02,13,122
3,1,460028714280225, qq,2015-05-03,1,1117
3,2,460028714280226,qq,2015-05-04,9,1118
3,3,460028714280227,qq,2015-05-05,10,120
1,1,460028714280218,360,2015-06-01,11,1118
1,2,460028714280219,qq,2015-06-02,2,1119
1,3,460028714280220,yy,2015-06-03,9,1120
1,4,460028714280221,360,2015-06-04,10,119
2,1,460028714280222, yy,2015-06-05,11,1118
2,2,460028714280223,360,2015-06-01,11,121
2,3,460028714280224,qq,2015-06-02,4,1119
3,1,460028714280225,qq,2015-06-03,17,119
3,2,460028714280226,qq,2015-06-04,19,1119
3,3,460028714280227,qq,2015-06-05,20,121*/



/*
*, second, the mobile Internet data loading and preprocessing
*/
The file is loaded first, and then the validity of the access record is judged by judging the number of fields per row of data.
Load the file and separate each row of records with a comma, and finally filter by the number of fields
Val Mobile = Sc.textfile ("./data/mobileinternet.txt"). Map (_.split (",")). filter{
Case line if (line.length! = bcfields.value.length) = False
Case _ = True
}


/*
* Three, different application usage statistics
*/
Simple statistics on the number of app field accesses
Mobile.map (x = (Bcfields.value.indexOf ("APP")), 1). Reducebykey (_+_)
. map (x = (x._2,x._1)). Sortbykey (FALSE). map (x = = (x._2,x._1)). Collect (). foreach (println)

Mobile.map (x = (Bcfields.value.indexOf ("APP")), 1). Reducebykey (_+_)
. map (x = (x._2,x._1)). Sortbykey (FALSE). map (x = = (x._2,x._1)). Repartition (1). Saveastextfile ("/result/ APPSTAT1 ")


/*
* Iv. statistics of dau and Mau on mobile internet data
*/
Dau and Mau statistics on mobile Internet data require attention to the user's deduplication: Each user is uniquely identified by the field IMEI. Statistics require removal of duplicate users.
Simple statistics on access to the Dau field
First, the IMEI field and the Time field are merged, then removed, and the time field is finally extracted from the merged data
Mobile.map (x = (Bcfields.value.indexOf ("IMEI") + ":" + x (bcfields.value.indexOf ("Time")))
. distinct (). Map (x = (X.split (":") (1), 1))
. Reducebykey (_+_). Sortbykey (). Collect (). foreach (println)

Simple statistics on access to the Mau field
Mobile.map {x =
Val t = x (Bcfields.value.indexOf ("Time"))
Val m = t.substring (0,t.lastindexof ("-"))
X (Bcfields.value.indexOf ("IMEI")) + ":" + M
}.distinct (). Map (x = (x. Split (":") (1), 1)). Reducebykey (_+_). Sortbykey (). Collect (). foreach (println)



/*
* Five, the traffic statistics on the mobile Internet data
*/
Mobile.map {x =
Val ub = x (bcfields.value.indexOf ("Uplinkbytes")). ToDouble
Val db = x (bcfields.value.indexOf ("Downlinkbytes")). ToDouble
(X (Bcfields.value.indexOf ("APP")), List[double] (ub,db))
}.reducebykey ((x, y) = List (× (0) + y (0), X (1) + y (1)). Collect (). foreach (println)


}

}

Simple Mobile Internet Data entry case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.