Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
added weekly, monthly import
Browse files Browse the repository at this point in the history
  • Loading branch information
max-wittig committed Jan 16, 2017
1 parent 35d3f40 commit 054c4c1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 13 deletions.
5 changes: 4 additions & 1 deletion data/config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"toAddress":"max@example.com",
"password":"Testing123",
"smtpHost": "smtp.example.com",
"port":500
"port":500,
"dailyReport": true,
"weeklyReport": false,
"monthlyReport": true
}
2 changes: 1 addition & 1 deletion src/com/maxwittig/reportgenerator/ReportType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum class ReportType
{
return MONTHLY
}

else
if(weeklyEnabled && isLastDayOfTheWeek())
{
return WEEKLY
Expand Down
22 changes: 14 additions & 8 deletions src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.maxwittig.reportgenerator.builder
import com.googlecode.jatl.Html
import com.maxwittig.reportgenerator.ReportType
import com.maxwittig.reportgenerator.models.TimekeeperTask
import com.maxwittig.reportgenerator.utils.getTimeStringFromSeconds
import java.io.File
import com.maxwittig.reportgenerator.utils.FileUtils
import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds
import java.io.StringWriter
import java.text.SimpleDateFormat
import java.util.*
Expand All @@ -23,7 +23,6 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
if(reportType == ReportType.MONTHLY && monthlyTasks.isNotEmpty())
{
body.h1().text("Your " + reportType.toString().toLowerCase() + " report").end()
body.h3().text("Your 10 longest tasks this month").end()
addMonthlyHTML(body)
}
else
Expand All @@ -33,8 +32,11 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
addWeeklyHTML(body)
}

body.br().end()
body.hr().end()
if(reportType != ReportType.DAILY)
{
body.br().end()
body.hr().end()
}

if(todayTasks.isNotEmpty())
{
Expand All @@ -51,12 +53,14 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
private fun addHead()
{
val head = html.head()
head.style().type("text/css").text(File("src/com/maxwittig/reportgenerator/builder/css/reportStyle.css").readText()).end()
val css = FileUtils.getFileContentFromJar("/com/maxwittig/reportgenerator/builder/css/reportStyle.css")
head.style().type("text/css").text(css).end()
head.end()
}

private fun addMonthlyHTML(body : Html)
{
body.h3().text("Your 10 longest tasks this month").end()
val format = SimpleDateFormat("dd.MM.yyyy - HH:mm:ss")
addTaskTable(monthlyTasks, body, format)
body.br()
Expand All @@ -71,8 +75,10 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
private fun addTodayHTML(body : Html)
{
val format = SimpleDateFormat("dd.MM.yyyy - HH:mm:ss")
body.h3().text("Daily Tasks")
addTaskTable(todayTasks, body, format)
body.br().end()
body.h3().text("Daily Projects")
addProjectTable(body, getDailyProjectTimeHashMap())
}

Expand All @@ -87,7 +93,7 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
//add projectname
tr.td().text(key).end()
//add duration
tr.td().text(getTimeStringFromSeconds(hashMap.get(key)!!)).end()
tr.td().text(getTimeStringFromMilliSeconds(hashMap.get(key)!!*1000)).end()
tr.end()
}

Expand Down Expand Up @@ -135,7 +141,7 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>,val reportTy
val row = tBody.tr()
row.td().text(format.format(task.startTime)).end()
row.td().text(format.format(task.endTime)).end()
row.td().text(getTimeStringFromSeconds(task.duration)).end()
row.td().text(getTimeStringFromMilliSeconds(task.duration*1000)).end()
row.td().text(task.projectName).end()
row.td().text(task.taskName).end()
row.end()
Expand Down
4 changes: 2 additions & 2 deletions src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.maxwittig.reportgenerator.builder

import com.maxwittig.reportgenerator.ReportType
import com.maxwittig.reportgenerator.models.TimekeeperTask
import com.maxwittig.reportgenerator.utils.getTimeStringFromSeconds
import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds
import com.maxwittig.reportgenerator.utils.isSameDay
import com.maxwittig.reportgenerator.utils.isSameMonth
import com.maxwittig.reportgenerator.utils.isSameWeek
Expand Down Expand Up @@ -93,7 +93,7 @@ abstract class ReportBuilder(private val timekeeperTasks : ArrayList<TimekeeperT
{
totalTime += task.duration
}
return getTimeStringFromSeconds(totalTime)
return getTimeStringFromMilliSeconds(totalTime*1000)
}

protected fun getMonthlyProjectTimeHashMap() : HashMap<String, Long>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class HTMLReportBuilderTest
File("data/testResults/monthly.html").writeText(reportBuilder.getReport())
}

@Test
fun dailyReportTest()
{
val taskList = getRandomTimekeeperTaskArrayList()
val now = getRandomDateInTheYear()
val reportBuilder = HTMLReportBuilder(taskList, ReportType.DAILY, todaysDate = now)
File("data/testResults/daily.html").writeText(reportBuilder.getReport())
}

private fun getRandomWordFromList() : String
{
return wordList[Random().nextInt(wordList.size)]
Expand Down
2 changes: 1 addition & 1 deletion src/com/maxwittig/reportgenerator/utils/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun isLastDayOfTheWeek() : Boolean
return now.dayOfWeek.value == 7
}

fun getTimeStringFromSeconds(totalTime : Long) : String
fun getTimeStringFromMilliSeconds(totalTime : Long) : String
{
val hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(totalTime),
TimeUnit.MILLISECONDS.toMinutes(totalTime) % TimeUnit.HOURS.toMinutes(1),
Expand Down
30 changes: 30 additions & 0 deletions src/com/maxwittig/reportgenerator/utils/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.maxwittig.reportgenerator.utils

import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.InputStreamReader


class FileUtils
{

companion object
{
fun getFileContentFromJar(path: String): String?
{
val inputStream = FileUtils::class.java.getResourceAsStream(path)
val bufferedInputStream = BufferedInputStream(inputStream)
val bufferedReader = BufferedReader(InputStreamReader(bufferedInputStream))
var line: String? = ""
val text = StringBuilder()

while (line != null)
{
line = bufferedReader.readLine()
if (line != null)
text.append(line)
}
return text.toString()
}
}
}

0 comments on commit 054c4c1

Please sign in to comment.