Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register report: group by #122

Merged
merged 3 commits into from
Jan 14, 2017
Merged

Register report: group by #122

merged 3 commits into from
Jan 14, 2017

Conversation

jaa127
Copy link
Contributor

@jaa127 jaa127 commented Dec 27, 2016

Hi, this PR implements groubBy option for register report. With groupBy it is possible to control Abandon's register reports grouping time span. This is handy if there is need to generate register report over month or week but with day resolution.

It might be that abandon's current register report is not exactly "register" report, but it is useful as it is and this groupBy adds handy feature to that report. For balance report and xml exports futher desing is needed before those are implemented, so that e.g. formatting is meaningful.

Register report grouping is based on year, month, day, isoWeek
or isoWeekDate. This can be selected with "groupBy" config-option.
Default is month, so if no groupBy option is defined, then behaviour
is unchanged.

This also changes Date.isoWeekDay -> isoWeekDate which is correct
term for ISO 8601 weekdate.
Use correct val names so they are not misleading (posts vs. txns),
for now this is done only in scope of groupBy.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 71.537% when pulling 3a1bde6 on jaa127:register-group-by into 6e13158 on hrj:master.


/**
* Grouping is done by truncated int numbers. The end result (groups) is
* Seq[(String, Seq[PostGroup])] so we need mapping from truncated intDate -> String
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what if we use strings through out for grouping? The integer values would be converted to a string before the grouping.

Copy link
Contributor Author

@jaa127 jaa127 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one option. However, probably in most of the cases, sorting is done by year, month or day. By doing sorting in these cases as Int should be much faster than purely string based sorting. However, I don't have any specific numbers. And it was kind of interesting to build that bifurcation. =)

}
}

case class RegisterReportSettings(_title: String, _accountMatch: Option[Seq[String]], _outFiles: Seq[String], groupBy: GroupBy) extends ReportSettings(_title, _accountMatch, _outFiles) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: private vals are being prefixed with _. It would be good to rename groupBy to _groupBy just for convention sake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, will fix this one!

sealed case class GroupByMonth() extends GroupBy
sealed case class GroupByDay() extends GroupBy
sealed case class GroupByIsoWeek() extends GroupBy
sealed case class GroupByIsoWeekDate() extends GroupBy
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider using object instead of case class. For example:

object GroupByYear extends GroupBy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later I like to use these as closed set enums, so that compiler can do exhaustive check in matchers. With objects that's not possible?
Especially here: https://github.com/hrj/abandon/pull/122/files#diff-4943d1460731e0560df4dd1a2f3a6088R444
Throw:n exception while figuring out user input is kind of ok (input/cfg validation), but later inside maps etc. is is not so nice. That was the reason behind sealed case class.

Use '_'-prefix for private variables.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 70.045% when pulling e90fd84 on jaa127:register-group-by into 6e13158 on hrj:master.

@jaa127
Copy link
Contributor Author

jaa127 commented Jan 14, 2017

Hi, here is update PR. I left those two other commented changes as they are. The sealed case class or some other exhaustive compiler checked enum should stay, but text grouping can go away, if it's complicating code base too much. But for overal performace reasons, it should be better if it stays.

Copy link
Owner

@hrj hrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I think using object preserves the exhaustiveness check. But we can do that later after the merge.

@hrj hrj merged commit e938c43 into hrj:master Jan 14, 2017
@jaa127
Copy link
Contributor Author

jaa127 commented Jan 14, 2017

Thanks for merging this!

I tried to change the case class to object, but then exhaustive checks did not work. Maybe I did something funky, but I think it must be case class?

@jaa127 jaa127 deleted the register-group-by branch January 14, 2017 13:58
@hrj hrj modified the milestone: Next release Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants