The output is sorted by day, but within the day outputs aren't sorted (or, rather, they're sorted by line number). Is this reliable behaviour (as-in, should I expect it to change at some point)?
The current source file for importing that I'm working on lists transaction in reverse chronological order (I want chronological, in this case) but also has a reference number that is monotonically increasing. So my current hack is to set line number for the transactions to be that reference number.
--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAGQ70es-roVBQnWUdeDedgCSNL6PBb4Z%2Bywyo3J5LYwseAjfUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, Nov 28, 2018 at 10:00 PM Oon-Ee Ng <ngoone...@gmail.com> wrote:The output is sorted by day, but within the day outputs aren't sorted (or, rather, they're sorted by line number). Is this reliable behaviour (as-in, should I expect it to change at some point)?- It's intended to be "stable," that is, between two runs, the order should be the same.- It's not intended to be something you should rely on, not the least reason which is that you may reorder input in your file. It may change if there's a good reason for it (but frankly I don't see any reason to right now).The current source file for importing that I'm working on lists transaction in reverse chronological order (I want chronological, in this case) but also has a reference number that is monotonically increasing. So my current hack is to set line number for the transactions to be that reference number.That seems not unlike the idea of storing the time in metadata - discussed in a prior thread but not yet implemented - and to use that as a secondary sort key. Maybe I can generalize this idea of a secondary sort key to let users put whatever they want in there (as long as the type is comparable, for sorting).
On 28/11/2018 23:22, Daniele Nicolodi wrote:
> On 28/11/2018 23:17, Martin Blais wrote:
>> On Thu, Nov 29, 2018 at 1:14 AM Oon-Ee Ng <ngoone...@gmail.com
>>
>> That was my impression as well, but after testing it out I found
>> this was not the case. The returned ordered list of transactions is
>> then sorted by date and line number.
>>
>>
>> Yes. Sorted by date.
>
> Is that documented?
>
> Would it be a possibility to accept a datetime object instead that a
> date object for the date field (and do not serialize the time part into
> the written file) be enough to obtain sorting by date and time?
>
> Actually, datetime objects are already accepted building metadata
> instances and I guess the sorting does not strip the time away, thus
> only the serialization would need to be changed. I guess I can prepare a
> patch for this.
The patch is easy enough and attached, although it is largely untested.
Hello Maetin,
On 29/11/2018 07:08, Martin Blais wrote:
> Let me get this right: you're proposing a patch that affects the parser
> layer, that has potential to break a bunch other people's stuff, and
> you're not bothering to write a test that specifically handles that case?
> This is a perfect example how not to contribute to a released open
> source project.
> I have no time for "largely untested" patches.
I think I didn't explain well enough what my idea is (however, if you
would have looked at the patch I believe you could have understood it
rather quickly).
The problem I tried to solve is that in the ingestion process, before
being serialized into a beancount file, entries are sorted by date,
type, and origin file line number. It has ben requested if the sorting
order could take into account transaction time.
The solution I proposed is to allow the ingestion machinery to accept a
datetime object for the date field. The time would be thrown out in the
serialization, but would be used for sorting. It is similar to using
time information stored in the meta field.
The implementation is simple as the only thing that needs to change is
the serialization in minimal part. After looking at the code the only
thing that needs to be done is to replace the string formatting for date
entries from ...format('{e,date} ...', e) to
...format('{e.date:%Y-%m-%d}...', e). There is no change to the parser
layer.
The patch does not come with tests because I thought to it as a better
description of the kind of solution I'm proposing, rather than something
ready to be merges.
I interpret your answer as very hostile (please correct me if this
impression is wrong). Thus I am happy that I haven't invested more time
in my attempt to contribute an idea to your project.
Best,
Dan
--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/f9097208-7347-1532-fcdb-5986dce3518e%40grinta.net.
So I came up with a workaround:
```
# Re-generate "lineno" to force sorting
for lineno, entry in enumerate(entries, start=1):
entry.meta['lineno'] = lineno
```
Just generate artificial "lineno" keys and insert them into the
transactions before returning them to Beancount. This way I can preserve
the order.
A possible approach to make both parties happy would be to add a new
parameter to "extract_from_file()" function, allowing importers to
disable the sorting behaviour in post-processings.
> --
> You received this message because you are subscribed to the Google Groups "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> beancount+...@googlegroups.com.
> To post to this group, send email to bean...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/
> CAGQ70esZ%2BSFkn4VcaG1dh%2BP1i%3DNgQ9rHvSdx-_8eVKvJ1%3DcRMg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
Zhuoyun Wei
--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20181129151330.GA28669%40tarball.wzyboy.org.
> I've agreed with others in previous threads to add
> 1. Support for the grammar to parse a time and to insert the time
> portion in some metadata field
I agree that extending the grammar to understand a type with date and
time information would be useful, but I don't see any advantage in
having it as part of the directive date in the file format, if it is not
used by beancount. Having a 'time' entry in the metadata could be
otherwise useful.
> 2. Adding an option to support specifying a secondary key for sorting
> This wouldn't break any of the current code by default.
Are you referring here to the sorting that is performed before
processing or before serialization in the ingest framework?
In the first case, I don't know what use case it solves, thus I cannot
comment. In the second case, I don't know what would be a good
interface to expose it.
Cheers,
Dan
--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/32d7f91e-84ab-fea3-e61c-3f0d3b83dae0%40grinta.net.
Cheers,
Dan
--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/35188815-baad-005e-6f80-eaacef6b91fb%40grinta.net.