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

how i calculate the total Number of tasks depend the value from KEY/VALUE list #180

Open
ashrafalzyoud opened this issue Aug 13, 2020 · 7 comments

Comments

@ashrafalzyoud
Copy link

ashrafalzyoud commented Aug 13, 2020

i have tow tracker
Traker Result id[1]
--> cfs [1] tybe integer = total number of Tasks if ( cfs[10] tybe key/value list =A)
--> cfs [2] tybe float = total values cfs [20] if ( cfs[10] tybe key/value list =A)

--> cfs [3] tybe integer = total number of Tasks if ( cfs[10] tybe key/value list =B)
--> cfs [4] tybe float = total values cfs [20] if ( cfs[10] tybe key/value list =B)

Traker company [2]
CFS [10] tybe (KEY/VALUE LIST ) the values A,B,C Rate the company
CFS[20] TYBE FLOAT = The value of the bill

like this if i have in company total Tasks 950, total bill 1000$
Traker Result its will look
cfs[1] = 400 number of Tasks
cfs[2]= 300 $ total bills

cfs[3]= 550 number of Tasks
cfs[4]= 700 $ total bills

i hope if u can help me

@ashrafalzyoud
Copy link
Author

ashrafalzyoud commented Aug 13, 2020

cfs[1] = Issue.where(traker_id: 2,custom_field_id: 10, value: "A").all.size
cfs[2]= total cfs[20(traker_id: 2,custom_field_id: 10, value: "A")].to_f.round(2)

cfs[3] = Issue.where(traker_id: 2,custom_field_id: 10, value: "B").all.size
cfs[4]= total cfs[20(traker_id: 2,custom_field_id: 10, value: "B")].to_f.round(2)

@ashrafalzyoud
Copy link
Author

ashrafalzyoud commented Aug 13, 2020

@AirTibu
I hope you will help me with appreciation and respect

@ashrafalzyoud ashrafalzyoud changed the title how i calculate the total Number of issues depend the value from KEY/VALUE list how i calculate the total Number of tasks depend the value from KEY/VALUE list Aug 13, 2020
@AirTibu
Copy link

AirTibu commented Aug 16, 2020

Hi,

There some contradictions in your first and second post, but as far as I understand, you need this code:

BEFORE SAVE

if tracker_id ==2
    @cf_key_value = CustomFieldEnumeration.where(:id=> custom_field_value(10).to_s,:custom_field_id => '10').first.to_s
    @issues_id_list = Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10'AND value = '#{custom_field_value(10).to_s}'").pluck(:id)
    @float_value = CustomValue.where("customized_id IN (#{@issues_id_list.join(',').to_s}) AND custom_field_id = '20'").pluck(:value)
    
    if @cf_key_value =="A"
        @issue.custom_field_values = { '1' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '2' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    elsif @cf_key_value =="B"
        @issue.custom_field_values = { '3' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '4' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    end
end

If you submit (save) an issue which is in tracker(2), then the code running. If I understand well, all custom_field is in tracker(2). Is it right?

But I'm pretty sure, that is not good solution, because in this case you should use hard coded company names.

In your second post you refer to tracker_id == 2 at all fields. Is it right?

cfs[1] = Issue.where( traker_id: 2 ,custom_field_id: 10, value: "A").all.size
cfs[2]= total cfs[20( traker_id: 2 ,custom_field_id: 10, value: "A")].to_f.round(2)
cfs[3] = Issue.where( traker_id: 2 ,custom_field_id: 10, value: "B").all.size
cfs[4]= total cfs[20( traker_id: 2,custom_field_id: 10, value: "B")].to_f.round(2)

@ashrafalzyoud
Copy link
Author

when i Execute this formula
tracker_id=2 its configure for three project ids( 1,2,3)
my question is, the effect formula only for what im choose project id (1)

@AirTibu
Copy link

AirTibu commented Sep 16, 2020

Hi,

In this case you need this code:



if tracker_id ==2 && project_id==1
    @cf_key_value = CustomFieldEnumeration.where(:id=> custom_field_value(10).to_s,:custom_field_id => '10').first.to_s
    @issues_id_list = Issue.joins(:custom_values).where("tracker_id = '2' AND project_id = '1' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").pluck(:id)
    @float_value = CustomValue.where("customized_id IN (#{@issues_id_list.join(',').to_s}) AND custom_field_id = '20'").pluck(:value)
    
    if @cf_key_value =="A"
        @issue.custom_field_values = { '1' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '2' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    elsif @cf_key_value =="B"
        @issue.custom_field_values = { '3' => Issue.joins(:custom_values).where("tracker_id = '2' AND project_id='1' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '4' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    end
end


@ashrafalzyoud
Copy link
Author

@float_value sum just only for tracker_id ==2 && project_id==1
or i will do somthings??

@ashrafalzyoud
Copy link
Author

@AirTibu #321

@ashrafalzyoud ashrafalzyoud reopened this Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants