-
Notifications
You must be signed in to change notification settings - Fork 736
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
Merge 20191117042320_add_cost_field_to_charges.exs (Charge Cost field) #258
Conversation
Okay, reading the ecto documentation I see that mix datatypes cannot be defined this way. I will need to do some more reading. |
|
||
def change do | ||
|
||
alter table(:charges) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cost field should be added to the :charging_processes
table. The naming could be better, I know :-)
use Ecto.Migration | ||
|
||
def change do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the formatter happy, you can run MIX_ENV=test mix format
A datatype like |
To apply the database migration there is mix ecto.migrate |
There is no charging cost interface either manual or automatic at this
point.
The motivation for the immediate addition of this column to the database is
for those who are able to populate the field without requiring the project
to implement a UI or function.
I do have some ideas around automatic cost calculation, including either by
geolocation or by tag per charging session, and perhaps with a default cost
- however ultimately these all result in a cost being associated with each
charging session, so I wouldn't think it would be any impediment to adding
it to postgres and grafana now? It is entirely possible that these wouldn't
be in scope for TeslaMate (that's entirely up to the developer) in which
case it may be an external module or process of some sort which then
updates the column. I am 99% sure that if it were not part of the
interface/project, someone (most likely myself at a minimum) would pick it
up as an add-on, as they could co-exist quite cleanly.
…On Fri, Nov 22, 2019 at 7:42 AM Marco Gabriel ***@***.***> wrote:
How will cost data get into that column?
I charge at different chargers. They apply different costs, some per
minute, some per kwh, some are free and some use a fixed fee per charge.
As a first step, I built a custom dashboard for me that just displays the
charges at home (location: home) and applies my kwh price on the gross kwh
consumption of the charge (fixed multiplication in the table, not even in
the database). That gives me an overview how much my car consumes at home
and what fraction of my power bill is caused by my car.
My approach is simple, but just covers cost at home.
Is there any other way than entering manually the charging type (minutes,
kwh, fix, free) and the location as a tuple?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#258>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGFF33C7VIVC4A5P4LXGSCLQU3XD3ANCNFSM4JOGE4JQ>
.
|
For me just a database column with a simple cost input per charging session would be great. By simple input I mean a simple to implement input (like just a field in the database) and not a user friendly input field in the web frontend. @ngardiner: Thanks for taking your time to contribute to this project and to this issue in particular! |
BTW, this is related to issue #185. |
Fix type definition and correct table (thanks @adriankumpf!)
Resolve required mix formatting
Huge thanks yet again @adriankumpf for the context around working with ecto/mix. I have fixed the formatting issues and properly defined the column datatype, and have tested it in my environment:
@adriankumpf, I think the next steps will be to have a think about the data entry mechanism for this. I don't think I would be very useful at all UI wise (at this point, anyway) but I have an idea that I want to run past you, before I work on a separate PR. Here's my thoughts, what do you think?
|
In addition to the mix migration test in v1.13.0-dev, I have also just run a quick test with a charger session. The logs show:
And the charging_processes table is updated without issue, with cost being empty:
All looks good. |
Just one more update from me, I've actually managed to already set the costs for all of my charges, and I've already updated the grafana dashboard, although not as part of this PR. The one thing I did want to mention is that I think it does make sense to leave the default value for this column as null, because I have been using the following method for setting the values:
I then either set the cost to 0.00 if the charging is free (for me, the majority are) or to the cost if it is paid charging. If we were to default the value to 0.00, it would make it very difficult as I'd need to review every charge entry to see if it is a free charge or not.
Below is a look at what it looks like in my grafana dashboard. It is accurate (even if it seems as though it isn't) because the vast majority of my charging is free destination charging currently. |
Another thought I have is whether grafana itself can allow users to update the cost column per charging session once I have updated the charges dashboard to show it per session? I have no idea if it's an option, but if so it may save us the UI work - I am going to follow it up. |
I wouldn't mind an add-on that covers the various ways to calculate charging costs at all. But in general, tracking charging costs is in scope for this project. What's kept me from implementing it so far is, that I personally have no need for this feature. Additionally, like you and @toerb said, charging costs can be calculated in various ways (automatic cost calculation etc.) and I just don't know the specific requirements people have.
That would be a great follow-up PR!
I think that's a good idea. It could be implemented very quickly. From my point of view, building a simple UI wouldn't be much trouble either, as long as it's only about annotating recorded charging sessions. I could do that next.
I don't think that's possible with Grafana. But I'll be happy if it proves to be otherwise. |
Perfect, I have thought some more about how this could be implemented and I'd see this as being a 3rd changeset, after the simple static charging cost code is integrated. I have some ideas around real-world use but in general I think the majority of people will be entering this statically (sometimes calculating charging from kWh alone will be inaccurate as there may be other costs involved or charging methods). For me, the only dynamic charging calculation I'd use would be for home charging based off my grid rates (even though I have solar, making it impossible to calculate accurately, so I'd still be logging worst case costs). Everything else for me would be on the amount invoiced which is not going to be effectively automated. It would also need to be a regularly executed routine or a dynamically generated value to be particularly useful - ie if I happen to charge after a charging rate is changed, I would want to be able to go back to the address record in TM and update the new charging rate and have it dynamically recalculated.
Just opened a new PR for this and the API functions, and given you've answered all the questions I had here I am confident I know what to try out next.
Perfect, something like the geo-fence link in Grafana would be perfect I think? I will update the dashboard with a link to something that could be used for this in the other PR.
Yep, you're 100% right - after some research I have come to the same conclusion. If only it were that easy :) |
Yeah, that'd be perfect! |
@ngardiner , I think this is the most practical way for anyone to add the cost information. |
Hi @adriankumpf,
Off the back of the feature request for adding costs to charging details, I wanted to see if I could propose a new database column for this.
I'm new to making a schema change this way so appreciate any feedback. Once I work out how it works, I'll update the development doco to explain the process.
I have modeled this on other schema changes I can see in the distribution, however I couldn't find an example of a datatype with arguments in the way that I have defined this one, and I am not sure how to make these migrations apply to my existing distribution, I have tried restarting teslamate but that doesn't seem to initiate it.
The reasoning for the datatype proposed is:
Once I know how best to test this, I'll test it on my distribution. Let me know if you would like me to approach this in a different way.