From 3a6c6b00eb4c62b24c5e5ca670142ac5a00d7847 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 18 Jun 2024 22:46:31 +0100 Subject: o --- conflicts.txt | 22 +++++++ conflicts_orig.txt | 15 +++++ foods.lua | 95 +++++++++++++++++++++++++++ index.php | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++ page.cgi | 120 ++++++++++++++++++++++++++++++++++ qs.lua | 26 ++++++++ 6 files changed, 466 insertions(+) create mode 100644 conflicts.txt create mode 100644 conflicts_orig.txt create mode 100644 foods.lua create mode 100644 index.php create mode 100755 page.cgi create mode 100644 qs.lua diff --git a/conflicts.txt b/conflicts.txt new file mode 100644 index 0000000..1d7a968 --- /dev/null +++ b/conflicts.txt @@ -0,0 +1,22 @@ +--- +soup: bean soup, tomato soup, squash soup +curry: chickpea curry, mj curry +potato: mash, jacket beans +greens: ramen, fast ramen, stir fry +tomato: tomato soup, mj spghet, mj curry +meat: chilli, gurger +beans: bean soup, chilli + +bean soup: soup, beans +tomato soup: soup, tomato +squash soup: soup +chickpea curry: curry +mj curry: curry, tomato +mash: potato +jacket beans: potato +ramen: greens +fast ramen: greens +stir fry: greens +mj spghet: tomato +chilli: meat, beans +gurger: meat diff --git a/conflicts_orig.txt b/conflicts_orig.txt new file mode 100644 index 0000000..92998e5 --- /dev/null +++ b/conflicts_orig.txt @@ -0,0 +1,15 @@ +bean soup: tomato soup, squash soup, bean soup, chilli +chickpea curry: mj curry, chickpea curry +chilli: chilli, gurger +fast ramen: fast ramen, ramen +gurger: jacket beans, chilli, gurger +jacket beans: jacket beans, mash, gurger +mash: jacket beans, mash +mj curry: mj spghet, mj curry, tomato soup, mj penne, chickpea curry +mj penne: mj spghet, mj curry, tomato soup, mj penne +mj spghet: mj spghet, mj curry, tomato soup, mj penne +ramen: fast ramen, ramen +squash soup: tomato soup, squash soup, bean soup +stir fry: stir fry, fast ramen, ramen +tomato soup: tomato soup, squash soup, bean soup, mj spghet, mj curry +vesto/egg: vesto/egg diff --git a/foods.lua b/foods.lua new file mode 100644 index 0000000..663e3da --- /dev/null +++ b/foods.lua @@ -0,0 +1,95 @@ +local foods = {} +local function f(name,tags,ing) + table.insert(foods,{ + name=name, + tags=tags, + ing=ing or {}, + }) +end + +f('*',{}) +f('mj spghet',{'tomato'},{ + broccoli=.5, + passata=1, + spaghetti=.3}) +f('mj curry',{'curry','tomato'},{ + broccoli=.5, + passata=1, + rice=.3}) +f('chilli',{'meat','beans'}) +f('stir fry',{'greens'},{ + kale=.3, + broccoli=.5, + noodles=1.5, + sweetcorn=.5, + mangetout=.5}) +f('jacket beans',{'potato'},{ + potatoes=5, + beans=2}) +f('mash',{'potato'},{ + potatoes=5, + peas=.3}) +f('vesto/egg',{},{ + egg=2, + vesto=.5, + ['black beans']=1, + spaghetti=.2}) +f('fast ramen',{'greens'},{ + ['instant ramen']=2, + broccoli=.5, + sweetcorn=.5}) +f('ramen',{'greens'},{ + ['ramen ingredients']=1}) +f('tomato soup',{'soup','tomato'},{ + ['tinned tomatoes']=3, + ['coconut milk']=1, + garlic=.5}) +f('squash soup',{'soup'},{ + squash=1, + onion=1, + garlic=.5, + ['vegetable stock']=.15, + ['coconut milk']=1}) +f('bean soup',{'soup','beans'},{ + onion=1, + garlic=.5, + pepper=1, + ['black beans']=3, + ['tinned tomatoes']=1, + ['vegetable stock']=.15, + lime=1}) +f('gurger',{'meat'},{ + ['bean burger']=2, + ['minced meat']=.25, + chips=1, + egg=1, + bun=4}) +f('chickpea curry',{'curry','chickpea'},{ + chickpea=2, + ['chopped tomato']=2, + lemon=1, + onion=2, + garlic=.5, + ginger=.5, + chilli=1}) +f('chickpea thing',{'chickpea'},{ + chickpea=1, + garlic=.5, + ginger=.5, + chilli=1, + rice=.3, +}) +f('pizza',{},{ + pizza=2, +}) +f('daniel beans',{},{ + ['black beans']=1, + pepper=.5, + garlic=.5, + rice=.3, +}) + + + + +return foods diff --git a/index.php b/index.php new file mode 100644 index 0000000..840d987 --- /dev/null +++ b/index.php @@ -0,0 +1,188 @@ + [], + 1 => ["brocolli" => .5, + "passata" => 1, + "spaghetti" => .3], + 2 => ["brocolli" => .5, + "passata" => 1, + "rice" => .3], + 3 => [], + 4 => ["kale" => .3, + "pak choi" => .5, + "brocolli" => .5, + "rice" => .3, + "sweetcorn" => .5, + "mangetout" => .5], + 5 => ["potatoes" => 5, + "beans" => 2], + 6 => ["potatoes" => 5, + "peas" => .3], + 7 => ["egg" => 2, + "vesto" => .5, + "black beans" => 1, + "spaghetti" => .2], + 8 => ["instant ramen" => 2, + "brocolli" => .5, + "sweetcorn" => .5], + 9 => ["noodles" => .5, + "pak choi" => .5, + "brocolli" => .5, + "chilli" => .5, + "sweetcorn" => .5, + "mangetout" => .5, + "garlic" => 1 + ], + 10 => ["tinned tomatoes" => 3, + "coconut milk" => 1, + "garlic" => .5], + 11 => ["squash" => 1, + "onion" => 1, + "garlic" => .5, + "vegetable stock" => .15, + "coconut milk" => 1], + 12 => ["onion" => 1, + "garlic" => .5, + "pepper" => 1, + "black beans" => 3, + "tinned tomatoes" => 1, + "vegetable stock" => .15, + "lime" => 1], + 13 => ["bean burger"=>2, + "minced meat" => .25, + "chips" => 1, + "egg" => 1, + "bun" => 4], + 14 => ["brocolli" => .5, + "passata" => 1, + "penne" => .5], + 15 => ["chickpea" => 2, + "chopped tomato" => 2, + "lemon" => 1, + "onion" => 2, + "garlic" => .5, + "ginger" => .5, + "chilli" => 1] +]; + +$GLOBALS["ingredientsList"] = []; +$GLOBALS["ingredients"] = []; + + +$GLOBALS["allowance"] = [999,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]; + +for($i =0;$i<14;$i++){ + if ($_POST[$i]==""){ + $_POST[$i]=0; + } + $GLOBALS["allowance"][$_POST[$i]]-=1; +} + + +function genSel($dayNum,$meal){ + $p = (int)$_POST[$dayNum*2+$meal]; + $dm = $dayNum*2 + $meal; + $o = ""; +} + +function genRow($dayNum){ + return "" . $GLOBALS["days"][($dayNum+5) % 7] . "" . genSel($dayNum,0) . "" . genSel($dayNum,1) . ""; +} + +for($i =0;$i<14;$i++){ + foreach($GLOBALS["mealingredients"][$_POST[$i]] as $key => $val){ + if(isset($GLOBALS["ingredients"][$key])){ + $GLOBALS["ingredients"][$key] += $val; + }else{ + $GLOBALS["ingredients"][$key] = $val; + } + } +} + +?> + + + + + + Food solver + + + + + + + + + +
+ + + + + + + +
\LunchDinner
+ + +
+ IngredientQty"; + + foreach($GLOBALS["ingredients"] as $key => $val){ + echo "" . $key . "" . $val . ""; + } + + echo ""; + } + ?> + + diff --git a/page.cgi b/page.cgi new file mode 100755 index 0000000..6743f91 --- /dev/null +++ b/page.cgi @@ -0,0 +1,120 @@ +#!/usr/bin/env lua + +local foods = require'foods' +local qs = require'qs' + +local days = { + "mon","tue","wed","thu","fri","sat","sun" +} + + +print"Content-type: text/html" +print"" + +local prev_foods = {} +local Q = {} +if os.getenv'REQUEST_METHOD' == 'POST' then + Q = qs.parse_qs(io.read()) + local log = assert(io.open("/home/rebecca/pr/food/LOG", "a+")) + log:write(os.date("%Y-%m-%dT%H:%M:%S")) + for i=0,13 do + local prev_food = assert(tonumber(Q[tostring(i)])) + prev_foods[i] = prev_food + log:write(" "..prev_food) + end + log:write("\n") + log:close() +else + for i=0,13 do + prev_foods[i] = 1 + end +end + +local counts = {} +for i = 0,13 do + counts[i] = (counts[i] or 0) + 1 +end +local start_day = tonumber(Q.start or 1) + +local function ok(fi, si) + return true +end + +local function sel(sel_ix) + local opts = {} + for food_ix,food in ipairs(foods) do + if food_ix == prev_foods[sel_ix] then + table.insert(opts, + '' + ) + elseif ok(food_ix, sel_ix) then + table.insert(opts, + '' + ) + end + end + return '' +end + +local function row(n) + local d = 1+((n+start_day-1)%7) + return '' + .. '' .. days[d] .. '' + .. '' .. sel(2*n) .. '' + .. '' .. sel(2*n+1) .. '' + +end + + +print[[ +
+ + + + + + + + + +]] +for n=0,6 do print(row(n)) end +print[[ +
\lunchdinner
+ +
+
+]] + +local ings = {} +for _,fx in pairs(prev_foods) do + local food = foods[fx] + for k,v in pairs(foods[fx].ing) do + ings[k] = (ings[k] or 0) + v + end +end +local i2 = {} +for k,v in pairs(ings) do + table.insert(i2,k) +end +table.sort(i2) +print'
' + +for _,g in ipairs(i2) do + print('
'..g..'
') + print('
'..ings[g]..'x
') +end +print'
' +for _,g in ipairs(i2) do + print(g..', ') +end diff --git a/qs.lua b/qs.lua new file mode 100644 index 0000000..70484b7 --- /dev/null +++ b/qs.lua @@ -0,0 +1,26 @@ +-- querystring and post body parsing + +local function urldecode(s) + return s:gsub('+',' ') + :gsub('%%(%x%x)',function(x) + return string.char(tonumber(x,16)) + end) +end + +local function parse_qs(s) + local ix = 1 + local res = {} + while true do + local _,next_ix,ek,ev = s:find("([^=]+)=([^&]*)&?",ix) + if not ek then break end + local k,v = urldecode(ek), urldecode(ev) + res[k] = v + ix = next_ix + 1 + end + return res +end + +return { + urldecode = urldecode, + parse_qs = parse_qs, +} -- cgit v1.2.3