-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* some formatting * 2023 wle conf * authorsContributedPerRegion * update PoiXwpfV * ttn reader * more warnings * lastMonth stat * lastMonth stat * typo * evict cache on parse exception * 2023 rating * update scalafmt * java-version: 11 for PR * java-version: 11 for appveyor * drop scala 2.12 * remove number * fix tests
- Loading branch information
Showing
26 changed files
with
917 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = 3.7.17 | ||
runner.dialect = scala213 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
scalawiki-bots/src/main/scala/org/scalawiki/bots/museum/ImageListParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
scalawiki-bots/src/main/scala/org/scalawiki/bots/np/TTN.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.scalawiki.bots.np | ||
|
||
import org.apache.poi.ss.usermodel.{Cell, CellType} | ||
|
||
case class TTN(ttn: String, | ||
date: String, | ||
route: String, | ||
sender: String, | ||
senderContact: String, | ||
receiver: String, | ||
receiverContact: String, | ||
description: String, | ||
mass: Double, | ||
places: Int, | ||
value: Double, | ||
cost: Double) { | ||
def month: String = date.split("\\.").tail.reverse.mkString(".") | ||
def year: String = date.split("\\.").last | ||
def yyMmDd: String = date.split("\\.").reverse.mkString(".") | ||
} | ||
|
||
object TTN { | ||
def apply(cells: Seq[Cell]): Option[TTN] = { | ||
if (cells.headOption.exists(_.getCellType == CellType.NUMERIC)) { | ||
Some( | ||
TTN( | ||
ttn = cells(1).getStringCellValue, | ||
date = cells(2).getStringCellValue, | ||
route = cells(3).getStringCellValue, | ||
sender = cells(4).getStringCellValue, | ||
senderContact = cells(5).getStringCellValue, | ||
receiver = cells(6).getStringCellValue, | ||
receiverContact = cells(7).getStringCellValue, | ||
description = cells(8).getStringCellValue, | ||
mass = cells(9).getNumericCellValue, | ||
places = cells(10).getNumericCellValue.toInt, | ||
value = cells(11).getNumericCellValue, | ||
cost = cells(12).getNumericCellValue | ||
) | ||
) | ||
} else None | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
scalawiki-bots/src/main/scala/org/scalawiki/bots/np/TTNReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package org.scalawiki.bots.np | ||
|
||
import org.apache.poi.xssf.usermodel.XSSFWorkbook | ||
|
||
import java.io.{File, FileInputStream} | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class Person(contact: String, ttns: Seq[TTN]) | ||
|
||
object Person { | ||
def receivers(ttns: Seq[TTN]) = { | ||
ttns.groupBy(_.receiverContact).map { | ||
case (contact, personReceived) => Person(contact, personReceived) | ||
} | ||
|
||
} | ||
} | ||
|
||
case class TTNData(ttns: Seq[TTN]) { | ||
|
||
val byMonth = | ||
ttns.groupBy(_.month).view.mapValues(_.map(_.cost).sum).toSeq.sortBy(_._1) | ||
val byYear = byMonth.groupMap { | ||
case (month, ttns) => month.split("\\.").head | ||
} { case (month, ttns) => ttns } | ||
|
||
def variousStat(): Unit = { | ||
val byYearAvg = | ||
byYear.view.mapValues(ttns => ttns.sum / ttns.size).toSeq.sortBy(_._1) | ||
|
||
val year2023 = ttns.filter(_.year == "2022") | ||
val lastYear: Seq[(Int, Seq[String])] = year2023 | ||
.groupBy(_.receiverContact) | ||
.view | ||
.mapValues(x => x.size) | ||
.map { | ||
case (contact, count) => (count, contact) | ||
} | ||
.groupBy(_._1) | ||
.view | ||
.mapValues { x => | ||
x.toSeq.map(_._2).distinct.sorted | ||
} | ||
.toSeq | ||
.sortBy(_._1) | ||
|
||
println(byMonth) | ||
println(byYearAvg) | ||
|
||
lastYear.filter(_._1 >= 5) foreach { | ||
case (count, people) => println(s"$count: $people") | ||
} | ||
|
||
// ttns.filter(x => x.receiverContact.contains("Мамон") && x.year == "2023").sortBy(_.yyMmDd).foreach { t => | ||
// println(s"${t.date}, ${t.description}, ${t.mass}, ${t.cost}") | ||
// } | ||
|
||
val distinct = year2023.map(_.receiverContact).distinct.size | ||
val all = year2023.size | ||
|
||
println(s"All: $all, distinct: $distinct") | ||
} | ||
|
||
} | ||
|
||
object TTNReader { | ||
def main(args: Array[String]): Unit = { | ||
val wlmNumbers = WlmContacts.getNumbers | ||
|
||
val dir = new File("c:\\wmua\\np") | ||
val ttns2023 = TTNData(readDir(dir)).ttns.filter(_.year == "2023") | ||
val ttnsLastMonth = ttns2023.filter { ttn => | ||
!ttn.receiverContact.contains("Корбут") && | ||
ttn.month == "2023.08" // || ttn.month == "2023.09" | ||
} | ||
println("Ttns: " + ttnsLastMonth.size) | ||
|
||
val wlmTtns = ttnsLastMonth.filter { ttn => | ||
wlmNumbers.exists(n => ttn.receiverContact.contains(n)) | ||
} | ||
val wlmTtnsWithIndex = wlmTtns.sortBy(_.yyMmDd).zipWithIndex.map(_.swap) | ||
println("wlm ttns: " + wlmTtnsWithIndex.size) | ||
// wlmTtnsWithIndex.foreach(println) | ||
val wlmTtnsNumbers = wlmTtns.map(_.ttn).toSet | ||
|
||
val nonWlmTtns = ttnsLastMonth | ||
.filterNot(ttn => wlmTtnsNumbers.contains(ttn.ttn)) | ||
.sortBy(_.yyMmDd) | ||
.zipWithIndex | ||
.map(_.swap) | ||
|
||
println("not wlm ttns: " + nonWlmTtns.size) | ||
// nonWlmTtns.foreach(println) | ||
// val receivers = ttnsLastMonth.map(_.receiverContact).distinct.sorted | ||
// println("receivers: " + receivers.size) | ||
// receivers.foreach(println) | ||
|
||
// ttns2023 | ||
// .filter(x => x.receiverContact.contains("380681234567") && x.year == "2023") | ||
// .sortBy(_.yyMmDd).zipWithIndex | ||
// .foreach { case (t, i) => | ||
// println(s"${i+1}. ${t.date}, ${t.description}, ${t.mass}, ${t.cost}, ${t.receiverContact}") | ||
// } | ||
|
||
} | ||
|
||
private def readDir(dir: File): Seq[TTN] = { | ||
val files = dir.listFiles().filter(_.getName.endsWith(".xlsx")) | ||
files.flatMap(readFile) | ||
} | ||
|
||
private def readFile(file: File): Seq[TTN] = { | ||
val fis = new FileInputStream(file) | ||
val workbook = new XSSFWorkbook(fis) | ||
val sheet = workbook.getSheetAt(0) | ||
val rowIterator = sheet.iterator.asScala | ||
rowIterator.toSeq.flatMap { row => | ||
TTN.apply(row.cellIterator.asScala.toSeq) | ||
} | ||
} | ||
|
||
def readWlmPhoneNumbers() = {} | ||
} |
41 changes: 41 additions & 0 deletions
41
scalawiki-bots/src/main/scala/org/scalawiki/bots/np/WlmContacts.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.scalawiki.bots.np | ||
|
||
object WlmContacts { | ||
|
||
private val Number = """[ +][\d\-()\s]{10,}""".r | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(getNumbers.size) | ||
getNumbers.foreach(println) | ||
} | ||
|
||
def getLines: Seq[String] = { | ||
Seq( | ||
" 0931234567", | ||
" 380671234567", | ||
" 063-123-45-67", | ||
" 097 123-45-67", | ||
" 095 123 45 67", | ||
" 095-1234567", | ||
" (097)1234567", | ||
" 380 (63) 123 45 67", | ||
" 38 050 123 45 67" | ||
) | ||
} | ||
|
||
def getNumbers: Seq[String] = { | ||
getLines.flatMap(getNumber) | ||
} | ||
|
||
def getNumber(line: String): Seq[String] = { | ||
Number | ||
.findAllIn(line) | ||
.toSeq | ||
.map(_.filter(_.isDigit)) | ||
.collect { | ||
case n if n.length == 10 => "38" + n | ||
case n if n.length == 12 => n | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
scalawiki-bots/src/test/scala/org/scalawiki/bots/np/WlmContactsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.scalawiki.bots.np | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
class WlmContactsSpec extends Specification{ | ||
|
||
"WlmContacts" should { | ||
val numbers = WlmContacts.getNumbers | ||
"pick 10 digits" in { | ||
numbers.contains("380931234567") === true | ||
} | ||
|
||
"pick 12 digits" in { | ||
numbers.contains("380671234567") === true | ||
} | ||
|
||
"pick dashed/spaced/braced digits" in { | ||
numbers.contains("380631234567") === true | ||
numbers.contains("380971234567") === true | ||
numbers.contains("380951234567") === true | ||
numbers.contains("380951234567") === true | ||
numbers.contains("380971234567") === true | ||
numbers.contains("380631234567") === true | ||
numbers.contains("380501234567") === true | ||
} | ||
} | ||
} |
Oops, something went wrong.