@@ -131,7 +131,7 @@ def get_balance_over_time
131131 def get_current_balances_with_friends
132132 id = get_current_user_id
133133 d = get_current_user_id
134- friends = { }
134+ friends = Hash . new ( - 1 )
135135 each_friendship do |friendship |
136136 candidates = friendship [ 'users' ] . reject { |u | u [ 'id' ] == id }
137137 throw "I find not 1 but #{ candidates . length } other users in a friendship." unless candidates . length == 1
@@ -143,11 +143,12 @@ def get_current_balances_with_friends
143143 def get_balances_over_time_with_friends
144144 id = get_current_user_id
145145 current_balances = get_current_balances_with_friends
146+ friend_keys = current_balances . keys . sort!
146147 balance_records = [ ]
147148 each_expense_newest_to_oldest do |expense |
148149 balance_records . push ( {
149150 'date' => expense [ 'date' ] ,
150- 'balances' => current_balances . values_at ( *current_balances . keys . sort! )
151+ 'balances' => current_balances . values_at ( *friend_keys )
151152 } )
152153 expense [ 'repayments' ] . each do |repayment |
153154 if repayment [ 'from' ] == id
@@ -292,6 +293,7 @@ def get_expenses_matching_cumulative query
292293
293294
294295#No longer useful:
296+
295297=begin
296298 def self.get_net_balances_over_time access_token
297299 expenses = []
@@ -397,4 +399,15 @@ def get_expenses_by_category_over_time #Exports in the form {categories: ["foo",
397399 'rows' => rows
398400 }
399401 end
402+ =end
403+
404+
405+ =begin
406+ def purge_deleted_friends hash #NB: this modifies the hash.
407+ hash.delete_if do |key, _|
408+ key == -1
409+ end
410+ end
411+
412+ private :purge_deleted_friends
400413=end
0 commit comments