zac

zac

How to sum (aggregate) from a `Time` attribute

I’ve been struggling to come up with an Ash aggregation or calculation that works on a Time attribute. The attribute in question:

    attribute :duration, :time do
      allow_nil? false
      public? true
    end

What I had thought would be a super-simple sum aggregation ended up… not working at all:

     * ** (Protocol.UndefinedError) protocol Enumerable not implemented for type Integer. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Iter, Jason.OrderedObject, LazyHTML, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Req.Response.Async, Rewrite, Stream, StreamData

Which led me down a path of a custom implementation, which became messy. Then I switched to a calculation. My calculation isn’t working yet, but it’s getting long and complicated and just seems like there should be a better (simpler) way.

I keep wondering if I’m missing something in the basic aggregate DSL syntax.

I can paste in my calculation if anyone wants to see it but at the moment it’s a mess. Hoping someone just points me at a better solution. :slight_smile:

First Post!

zachdaniel

zachdaniel

Creator of Ash

Can you share the stack trace of that error? And show your sum aggregate?

Most Liked

zachdaniel

zachdaniel

Creator of Ash

:thinking: might be worth checking what happens if your times sum up to greater than 24 hours :wink:

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement