nom 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7631851ac3b0706686593b269cf49b21d8de8599
4
- data.tar.gz: 98c3d3b7f73cb9ee660c33d3e8f60385e6049183
2
+ SHA256:
3
+ metadata.gz: 9552983cfcde8485668665b06976e054a7221c131d0dc134c9aa0cb435818f2b
4
+ data.tar.gz: 81568f52af092e92e20c4252b1073b0b8e5ac06c3629e63a50714d06744c89e2
5
5
  SHA512:
6
- metadata.gz: 8d485c873e3f738c69be2d4ffa997677062a43c0c083346c5a4ba2655a4230ec2b5524d27f301d0e160add5b18865ea454924b7bb258c41ab6a78fa5e8bd4493
7
- data.tar.gz: fb82204147412eace494619adf76e7d447af500baf9567b9182656ac16ddfc5f8590580f4ca94b07bbb2215d4cdc8c3a67966732414c683bda4775b0c882b8e5
6
+ metadata.gz: f96691c27e135e7399e5e2b2df338a0a6b89f70e98e5d0470b31aeff066719f77a0728bc112027ca450411d2e9fef9b70d41bad2eb3cc3deddf5e28c8fd6f8d7
7
+ data.tar.gz: 9350d1aedf1cbeeaee8f99f47aee4026dd2bf0e4ec0619c315d99ba76f2e1fdd64cd4b67ad02ba7f235d7b167dee18a8d5e7f284aa9df0f727d0cf6971bda3c8
data/README.md CHANGED
@@ -59,7 +59,7 @@ And get nice graphs. The upper graph shows weight over time, with a weighted (no
59
59
 
60
60
  $ nom plot
61
61
 
62
- ![Graphs of weight and input over time](http://files.morr.cc/nom-0.1.0.svg)
62
+ ![Graphs of weight and input over time](http://files.blinry.org/nom-0.1.0.svg)
63
63
 
64
64
  Enter `nom help` if you're lost:
65
65
 
@@ -91,9 +91,14 @@ Enter `nom help` if you're lost:
91
91
 
92
92
  ## Conventions
93
93
 
94
- *nom* operates on three files in the directory `~/.nom/`: `config` contains configuration settings, `input` contains stuff you ate, `weight` contains weight measurements. You can edit them by hand.
94
+ *nom* looks for its configuration directory in `${XDG_DATA_HOME}/nom`, `~/.local/share/nom`, or `~/.nom/` (in that order),
95
+ and operates on three files in that configuration directory:
96
+ * `config` contains configuration settings
97
+ * `input` contains stuff you ate
98
+ * `weight` contains weight measurements.
99
+ The files are plain text, you can edit them by hand.
95
100
 
96
- By default, energy quantities will have the unit "kcal". You can change this by adding a line like `unit: 0.239` to your `~/.nom/config`, which means you want to use the unit "0.239 kcal" (= "1 kJ"). Energy quantities are displayed in parentheses: `(42)`
101
+ By default, energy quantities will have the unit "kcal". You can change this by adding a line like `unit: 0.239` to your `config`, which means you want to use the unit "0.239 kcal" (= "1 kJ"). Energy quantities are displayed in parentheses: `(42)`
97
102
 
98
103
  Weight quantities are displayed as "kg", but you can use arbitrary units, like pounds.
99
104
 
data/bin/nom CHANGED
@@ -19,9 +19,19 @@ commands = [
19
19
  [ "help", nil, nil, "Print this help" ],
20
20
  ]
21
21
 
22
+ aliases = {
23
+ "--help": "help",
24
+ "-h": "help",
25
+ }
26
+
22
27
  nom = Nom::Nom.new
23
28
 
24
- cmd_name = ARGV.shift or "status"
29
+ cmd_name = (ARGV.shift or "status")
30
+
31
+ if aliases.include? cmd_name.to_sym
32
+ cmd_name = aliases[cmd_name.to_sym]
33
+ end
34
+
25
35
  command = commands.find{|c| c[0] == cmd_name or c[1] == cmd_name}
26
36
 
27
37
  if command.nil?
data/lib/nom/nom.plt.erb CHANGED
@@ -1,4 +1,4 @@
1
- set terminal svg size 1440,900 font "Linux Biolinum,20"
1
+ set terminal svg size 1920,1080 font "Linux Biolinum,20"
2
2
  set output "<%= svg.path %>"
3
3
 
4
4
  set multiplot layout 2,1
data/lib/nom/nom.rb CHANGED
@@ -13,8 +13,16 @@ require "nom/helpers"
13
13
  module Nom
14
14
  class Nom
15
15
  def initialize
16
- @nom_dir = File.join(Dir.home,".nom")
17
- if not Dir.exists? @nom_dir
16
+ xdg_data = (ENV["XDG_DATA_HOME"] or File.join(Dir.home, ".local", "share"))
17
+ preferred_config_location = File.join(xdg_data, "nom")
18
+ [ preferred_config_location, File.join(Dir.home,".nom") ].each do |dir|
19
+ if Dir.exists? dir
20
+ @nom_dir = dir
21
+ break
22
+ end
23
+ end
24
+ if not @nom_dir or not Dir.exists? @nom_dir
25
+ @nom_dir = preferred_config_location
18
26
  puts "Creating #{@nom_dir}"
19
27
  Dir.mkdir(@nom_dir)
20
28
  end
@@ -34,9 +42,9 @@ module Nom
34
42
  end
35
43
 
36
44
  @weights.interpolate_gaps!
37
- @weights.precompute_moving_average!(0.1, 0.1, goal, rate)
45
+ @weights.precompute_moving_average!(0.05, 0.05, goal, rate)
38
46
  @weights.predict_weights!(rate, goal, 30)
39
- @weights.precompute_moving_average!(0.1, 0.1, goal, rate)
47
+ @weights.precompute_moving_average!(0.05, 0.05, goal, rate)
40
48
 
41
49
  precompute_inputs_at
42
50
  precompute_base_rate_at
@@ -106,13 +114,13 @@ module Nom
106
114
  term = args.join(" ")
107
115
  puts
108
116
  term = term.encode("ISO-8859-1")
109
- url = "http://fddb.info/db/de/suche/?udd=0&cat=site-de&search=#{URI.escape(term)}"
117
+ url = "https://fddb.info/db/de/suche/?udd=0&cat=site-de&search=#{CGI.escape(term)}"
110
118
 
111
- page = Nokogiri::HTML(open(url))
119
+ page = Nokogiri::HTML(URI.open(url))
112
120
  results = page.css(".standardcontent a").map{|a| a["href"]}.select{|href| href.include? "lebensmittel"}
113
121
 
114
122
  results[0..4].each do |result|
115
- page = Nokogiri::HTML(open(result))
123
+ page = Nokogiri::HTML(URI.open("https://fddb.info"+result))
116
124
  title = page.css(".breadcrumb a").last.text
117
125
  brand = page.css(".standardcontent p a").select{|a| a["href"].include? "hersteller"}.first.text
118
126
  puts "#{title} (#{brand})"
@@ -121,7 +129,7 @@ module Nom
121
129
  size = serving.css("a.servb").text
122
130
  kcal = serving.css("div")[5].css("div")[1].text.to_i
123
131
  #kj = serving.css("div")[2].css("div")[1].text.to_i
124
- puts " (#{quantize(kcal)}) #{size}"
132
+ puts " (#{quantize(kcal,1)}) #{size}"
125
133
  end
126
134
  end
127
135
  end
@@ -306,8 +314,8 @@ module Nom
306
314
  end
307
315
  end
308
316
 
309
- def quantize kcal
310
- (1.0*kcal/@config.get("unit")).round
317
+ def quantize kcal, decimal_places=0
318
+ (1.0*kcal/@config.get("unit")).round(decimal_places)
311
319
  end
312
320
 
313
321
  def dequantize number
@@ -349,17 +357,16 @@ module Nom
349
357
  def log_since start
350
358
  remaining = 0
351
359
  start.upto(Date.today) do |date|
352
- remaining += allowed_kcal(date)
353
360
  puts
354
361
  puts "#{format_date(date)}: (#{quantize(allowed_kcal(date))})"
355
362
  puts
356
- remaining = allowed_kcal(date)
363
+ remaining = quantize(allowed_kcal(date))
357
364
  inputs_at(date).each do |i|
358
365
  entry(quantize(i.kcal), i.description)
359
- remaining -= i.kcal
366
+ remaining -= quantize(i.kcal)
360
367
  end
361
368
  separator
362
- entry(quantize(remaining), "remaining (#{(100-100.0*quantize(remaining)/quantize(allowed_kcal(date))).round}% used)")
369
+ entry(remaining, "remaining (#{(100-100.0*remaining/quantize(allowed_kcal(date))).round}% used)")
363
370
  end
364
371
  if kcal_balance > 0 and @config.has("balance_start")
365
372
  cost = if @config.has("balance_factor")
@@ -27,7 +27,7 @@ module Nom
27
27
  end
28
28
 
29
29
  def precompute_moving_average!(alpha, beta, goal, rate)
30
- trend = dampened_rate(@weights[first], goal, rate)/7.0
30
+ trend = 0
31
31
 
32
32
  @moving_averages[first] = at(first)
33
33
  (first+1).upto(last).each do |d|
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - Sebastian Morr
8
- autorequire:
7
+ - blinry
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-13 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -29,7 +29,7 @@ description: |-
29
29
  tracking your energy intake and creating a negative feedback loop.
30
30
  It's inspired by John Walker's "The Hacker's Diet" and tries to
31
31
  automate things as much as possible.
32
- email: sebastian@morr.cc
32
+ email: mail@blinry.org
33
33
  executables:
34
34
  - nom
35
35
  extensions: []
@@ -47,7 +47,7 @@ homepage: https://github.com/blinry/nom
47
47
  licenses:
48
48
  - GPL-2.0+
49
49
  metadata: {}
50
- post_install_message:
50
+ post_install_message:
51
51
  rdoc_options: []
52
52
  require_paths:
53
53
  - lib
@@ -63,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements:
65
65
  - gnuplot
66
- rubyforge_project:
67
- rubygems_version: 2.5.1
68
- signing_key:
66
+ rubygems_version: 3.3.21
67
+ signing_key:
69
68
  specification_version: 4
70
69
  summary: Lose weight and hair through stress and poor nutrition
71
70
  test_files: []