nom 0.1.2.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d7a87ec103978016261d62cf23b12b9e60eb934
4
- data.tar.gz: bac40aa74886759b48f5d73619161a446caac995
3
+ metadata.gz: 7631851ac3b0706686593b269cf49b21d8de8599
4
+ data.tar.gz: 98c3d3b7f73cb9ee660c33d3e8f60385e6049183
5
5
  SHA512:
6
- metadata.gz: 998227f0dac4058c6e27f59e26d826f0b60aff73d01307858154387cde2b90e7182ebb516e7a66a475f1c842d7fcdd952ac19172b1ddaff4fdcb9a5da07704a0
7
- data.tar.gz: 819cb06d3bcb5eb9f7337f855a60e84508cf2c38105fc74eb97141a5c05f3057c42432d8c35a314b12479a873630d5e69a3f1f599aaf872e2d78df9962a8b23b
6
+ metadata.gz: 8d485c873e3f738c69be2d4ffa997677062a43c0c083346c5a4ba2655a4230ec2b5524d27f301d0e160add5b18865ea454924b7bb258c41ab6a78fa5e8bd4493
7
+ data.tar.gz: fb82204147412eace494619adf76e7d447af500baf9567b9182656ac16ddfc5f8590580f4ca94b07bbb2215d4cdc8c3a67966732414c683bda4775b0c882b8e5
@@ -18,6 +18,7 @@ module Nom
18
18
  "unit" => [ "your desired base unit in kcal", 1, Float ],
19
19
  "start_date" => [ "the first day that should be considered by nom [yyyy-mm-dd]", nil, Date ],
20
20
  "balance_start" => [ "the day from which on nom should keep track of a energy balance [yyyy-mm-dd]", nil, Date ],
21
+ "balance_factor" => [ "how many money units you'll have to pay per energy unit", 0.01, Float ],
21
22
  }
22
23
  end
23
24
 
@@ -31,7 +31,7 @@ plot <%= goal %> t "Goal" lc rgb "forest-green" lw 2, \
31
31
  unset obj 1
32
32
 
33
33
  set yrange [ 0 : <%= quantize((@weights.first..@weights.last).map{|d| [consumed_at(d), allowed_kcal(d, 0), allowed_kcal(d, rate)]}.flatten.max) %> ]
34
- set ytics 200 nomirror
34
+ set ytics <%= quantize(200) %> nomirror
35
35
  set key right bottom
36
36
 
37
37
  plot "<%= input_dat.path %>" using 1:2:(0):($4-$2) w vectors nohead lc rgb "navy" notitle, \
@@ -201,11 +201,13 @@ module Nom
201
201
 
202
202
  def nom_entry args, date
203
203
  summands = args.pop.split("+")
204
- kcal = summands.inject(0) do |sum, summand|
204
+ number = summands.inject(0) do |sum, summand|
205
205
  factors = summand.split("x")
206
206
  sum + factors.map{ |f| f.to_f }.inject(1){ |p,f| p*f }
207
207
  end
208
208
 
209
+ kcal = dequantize(number)
210
+
209
211
  if kcal == 0
210
212
  raise "energy term cannot be zero"
211
213
  end
@@ -233,8 +235,8 @@ module Nom
233
235
  if r.nil?
234
236
  r = @weights.rate_at(date, goal, rate)
235
237
  end
236
- if date > @weights.last
237
- date = @weights.last
238
+ if date > @weights.last_real
239
+ date = @weights.last_real
238
240
  end
239
241
  @base_rate_at[date] + r*1000
240
242
  end
@@ -305,7 +307,11 @@ module Nom
305
307
  end
306
308
 
307
309
  def quantize kcal
308
- return (1.0*kcal/@config.get("unit")).round
310
+ (1.0*kcal/@config.get("unit")).round
311
+ end
312
+
313
+ def dequantize number
314
+ (1.0*number*@config.get("unit")).round
309
315
  end
310
316
 
311
317
  def format_date date
@@ -353,10 +359,15 @@ module Nom
353
359
  remaining -= i.kcal
354
360
  end
355
361
  separator
356
- entry(quantize(remaining), "remaining (#{(100-100.0*remaining/allowed_kcal(date)).round}% used)")
362
+ entry(quantize(remaining), "remaining (#{(100-100.0*quantize(remaining)/quantize(allowed_kcal(date))).round}% used)")
357
363
  end
358
- if kcal_balance > 0
359
- entry(quantize(kcal_balance.abs), "too much since #{balance_start}")
364
+ if kcal_balance > 0 and @config.has("balance_start")
365
+ cost = if @config.has("balance_factor")
366
+ " (cost: %.2f)" % (@config.get("balance_factor")*quantize(kcal_balance)).round(2)
367
+ else
368
+ ""
369
+ end
370
+ entry(quantize(kcal_balance), "too much since #{balance_start}#{cost}")
360
371
  end
361
372
  end
362
373
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Morr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - gnuplot
66
66
  rubyforge_project:
67
- rubygems_version: 2.4.5
67
+ rubygems_version: 2.5.1
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Lose weight and hair through stress and poor nutrition