Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs449 Template M2 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Manuel Serge Lanfranchi
Cs449 Template M2 2022
Commits
4621019d
Commit
4621019d
authored
4 years ago
by
Erick Lavoie
Browse files
Options
Downloads
Patches
Plain Diff
Added missing file
parent
6195eb7d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+10
-0
10 additions, 0 deletions
.gitignore
src/main/scala/stats/Analyzer.scala
+71
-0
71 additions, 0 deletions
src/main/scala/stats/Analyzer.scala
with
81 additions
and
0 deletions
.gitignore
0 → 100644
+
10
−
0
View file @
4621019d
.DS_Store
.bsp
**/*.swp
data/.DS_Store
data/ml-100k
project/project
project/target
src/main/scala/project/
src/main/scala/target/
target/
This diff is collapsed.
Click to expand it.
src/main/scala/stats/Analyzer.scala
0 → 100644
+
71
−
0
View file @
4621019d
package
stats
import
org.rogach.scallop._
import
org.json4s.jackson.Serialization
import
org.apache.spark.rdd.RDD
import
org.apache.spark.sql.SparkSession
import
org.apache.log4j.Logger
import
org.apache.log4j.Level
class
Conf
(
arguments
:
Seq
[
String
])
extends
ScallopConf
(
arguments
)
{
val
data
=
opt
[
String
](
required
=
true
)
val
json
=
opt
[
String
]()
verify
()
}
case
class
Rating
(
user
:
Int
,
item
:
Int
,
rating
:
Double
)
object
Analyzer
extends
App
{
// Remove these lines if encountering/debugging Spark
Logger
.
getLogger
(
"org"
).
setLevel
(
Level
.
OFF
)
Logger
.
getLogger
(
"akka"
).
setLevel
(
Level
.
OFF
)
val
spark
=
SparkSession
.
builder
()
.
master
(
"local[1]"
)
.
getOrCreate
()
spark
.
sparkContext
.
setLogLevel
(
"ERROR"
)
println
(
""
)
println
(
"******************************************************"
)
var
conf
=
new
Conf
(
args
)
println
(
"Loading data from: "
+
conf
.
data
())
val
dataFile
=
spark
.
sparkContext
.
textFile
(
conf
.
data
())
val
data
=
dataFile
.
map
(
l
=>
{
val
cols
=
l
.
split
(
"\t"
).
map
(
_
.
trim
)
Rating
(
cols
(
0
).
toInt
,
cols
(
1
).
toInt
,
cols
(
2
).
toDouble
)
})
assert
(
data
.
count
==
100000
,
"Invalid data"
)
// Save answers as JSON
def
printToFile
(
content
:
String
,
location
:
String
=
"./answers.json"
)
=
Some
(
new
java
.
io
.
PrintWriter
(
location
)).
foreach
{
f
=>
try
{
f
.
write
(
content
)
}
finally
{
f
.
close
}
}
conf
.
json
.
toOption
match
{
case
None
=>
;
case
Some
(
jsonFile
)
=>
{
var
json
=
""
;
{
// Limiting the scope of implicit formats with {}
implicit
val
formats
=
org
.
json4s
.
DefaultFormats
val
answers
:
Map
[
String
,
Any
]
=
Map
(
"3.1.1"
->
Map
(
"global-avg-rating"
->
3.0
)
)
json
=
Serialization
.
writePretty
(
answers
)
}
println
(
json
)
println
(
"Saving answers in: "
+
jsonFile
)
printToFile
(
json
,
jsonFile
)
}
}
println
(
""
)
spark
.
close
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment