Skip to content

Commit cf33d33

Browse files
committed
scalafmt
1 parent d74a657 commit cf33d33

File tree

2 files changed

+69
-43
lines changed

2 files changed

+69
-43
lines changed

.github/scripts/plot.scala

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,29 @@ object Plot {
3434
}
3535
}
3636

37-
def csvToBars(dir: File, allowedVersion: String => Boolean, filterOutMonths: Set[YearMonth] = Set()): Seq[Trace] = {
37+
def csvToBars(
38+
dir: File,
39+
allowedVersion: String => Boolean,
40+
filterOutMonths: Set[YearMonth] = Set()
41+
): Seq[Trace] = {
3842

3943
val data = for {
4044
year <- 2015 to Year.now(ZoneOffset.UTC).getValue
4145
month <- 1 to 12
4246
f = new File(dir, f"$year/$month%02d.csv")
4347
if f.exists()
4448
ym = YearMonth.of(year, month)
45-
elem <- CSVReader.open(f)
49+
elem <- CSVReader
50+
.open(f)
4651
.iterator
4752
.map(l => (ym, /* version */ l(0), /* downloads */ l(1).toInt))
48-
.collect { case (date, version @ relevantVersion(major, minor, patch), downloads) if allowedVersion(version) =>
49-
(date, (major, minor, patch), downloads)
53+
.collect {
54+
case (
55+
date,
56+
version @ relevantVersion(major, minor, patch),
57+
downloads
58+
) if allowedVersion(version) =>
59+
(date, (major, minor, patch), downloads)
5060
}
5161
.toVector
5262
} yield elem
@@ -76,30 +86,44 @@ object Plot {
7686
for {
7787
artifact <- stats.Params.artifacts
7888
(baseDir, divId, title) <- Seq(
79-
("per-version-stats", s"${artifact}-total", s"${artifact} (total downloads)"),
80-
("per-version-unique-ips", s"${artifact}-unique", s"${artifact} (unique IPs)")
89+
(
90+
"per-version-stats",
91+
s"${artifact}-total",
92+
s"${artifact} (total downloads)"
93+
),
94+
(
95+
"per-version-unique-ips",
96+
s"${artifact}-unique",
97+
s"${artifact} (unique IPs)"
98+
)
8199
)
82-
bars = csvToBars(dataBase.resolve(baseDir).resolve(artifact).toFile, _ => true /* keep all the versions */)
83-
} yield
84-
s"""
85-
|<h2 id="${divId}-plot">${title} <a href="#${divId}-plot">#</a></h2>
86-
|<div id="${divId}"></div>
87-
|<script>${Plotly.jsSnippet(divId, bars, Layout(barmode = BarMode.Stack))}</script>
88-
|""".stripMargin
100+
bars = csvToBars(
101+
dataBase.resolve(baseDir).resolve(artifact).toFile,
102+
_ => true /* keep all the versions */
103+
)
104+
} yield s"""
105+
|<h2 id="${divId}-plot">${title} <a href="#${divId}-plot">#</a></h2>
106+
|<div id="${divId}"></div>
107+
|<script>${Plotly.jsSnippet(
108+
divId,
109+
bars,
110+
Layout(barmode = BarMode.Stack)
111+
)}</script>
112+
|""".stripMargin
89113

90114
val html =
91115
s"""<!DOCTYPE html>
92-
|<html>
93-
|<head>
94-
|<title>Scalafix Statistics</title>
95-
|<script src="https://cdn.plot.ly/plotly-${Plotly.plotlyVersion}.min.js"></script>
96-
|</head>
97-
|<body>
98-
|<h1>Scalafix Statistics</h1>
99-
|${htmlSnippets.mkString}
100-
|</body>
101-
|</html>
102-
|""".stripMargin
116+
|<html>
117+
|<head>
118+
|<title>Scalafix Statistics</title>
119+
|<script src="https://cdn.plot.ly/plotly-${Plotly.plotlyVersion}.min.js"></script>
120+
|</head>
121+
|<body>
122+
|<h1>Scalafix Statistics</h1>
123+
|${htmlSnippets.mkString}
124+
|</body>
125+
|</html>
126+
|""".stripMargin
103127

104128
Files.createDirectories(dataBase)
105129
Files.write(dataBase.resolve("index.html"), html.getBytes("UTF-8"))

.github/scripts/sonatype-stats.scala

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ object Params {
5151
}
5252

5353
case class Data(
54-
base: Path,
55-
ext: String,
56-
empty: String => Boolean,
57-
name: String,
58-
tpe: String,
59-
projId: String,
60-
organization: String,
61-
artifact: Option[String]
54+
base: Path,
55+
ext: String,
56+
empty: String => Boolean,
57+
name: String,
58+
tpe: String,
59+
projId: String,
60+
organization: String,
61+
artifact: Option[String]
6262
) {
6363

6464
def fileFor(monthYear: YearMonth): Path = {
@@ -81,7 +81,8 @@ case class Data(
8181
val year = monthYear.getYear
8282
val month = monthYear.getMonth.getValue
8383

84-
uri"https://oss.sonatype.org/service/local/stats/$name?p=$projId&g=$organization&a=${artifact.getOrElse("")}&t=$tpe&from=${f"$year%04d$month%02d"}&nom=1"
84+
uri"https://oss.sonatype.org/service/local/stats/$name?p=$projId&g=$organization&a=${artifact
85+
.getOrElse("")}&t=$tpe&from=${f"$year%04d$month%02d"}&nom=1"
8586
}
8687

8788
def process(monthYears: Iterator[YearMonth]): Iterator[(YearMonth, Boolean)] =
@@ -90,13 +91,12 @@ case class Data(
9091
!exists(monthYear)
9192
}
9293
.map { monthYear =>
93-
9494
val u = urlFor(monthYear)
9595

9696
System.err.println(s"Getting $monthYear: $u")
9797

98-
val statResp = sttp
99-
.auth.basic(Params.sonatypeUser, Params.sonatypePassword)
98+
val statResp = sttp.auth
99+
.basic(Params.sonatypeUser, Params.sonatypePassword)
100100
.header("Accept", "application/json")
101101
.get(u)
102102
.send()
@@ -121,8 +121,8 @@ object SonatypeStats {
121121
def collect(): Unit = {
122122
val projId: String = {
123123
val projectIds: Map[String, String] = {
124-
val projResp = sttp
125-
.auth.basic(Params.sonatypeUser, Params.sonatypePassword)
124+
val projResp = sttp.auth
125+
.basic(Params.sonatypeUser, Params.sonatypePassword)
126126
.header("Accept", "application/json")
127127
.get(uri"https://oss.sonatype.org/service/local/stats/projects")
128128
.send()
@@ -167,14 +167,16 @@ object SonatypeStats {
167167

168168
for (data <- artifactStatsPerVersion) {
169169
val it = Iterator.iterate(Params.start)(_.minusMonths(1L))
170-
val processed = data.process(it)
171-
.takeWhile {
172-
case (monthYear, nonEmpty) =>
173-
nonEmpty || monthYear.compareTo(Params.cutOff) >= 0
170+
val processed = data
171+
.process(it)
172+
.takeWhile { case (monthYear, nonEmpty) =>
173+
nonEmpty || monthYear.compareTo(Params.cutOff) >= 0
174174
}
175175
.length
176176

177-
System.err.println(s"Processed $processed months in ${data.base} for type ${data.tpe}")
177+
System.err.println(
178+
s"Processed $processed months in ${data.base} for type ${data.tpe}"
179+
)
178180
}
179181
}
180182

0 commit comments

Comments
 (0)