数据分析CLI数据可视化【免费下载链接】visidataA terminal spreadsheet multitool for discovering and arranging data项目地址https://gitcode.com/gh_mirrors/vi/visidata点击查看免费下载导读Noahs Tapestry诺亚的挂毯是 VisiData 仓库中内置的一个交互式数据解谜游戏它把一段虚构的诺亚市场Noahs Market家族故事拆解为 9 道谜题玩家需要在一套真实的 SQLite 业务数据库客户、订单、商品里用 VisiData 或 SQL 检索线索、找出答案。本文聚焦Puzzle 6——一段关于表亲与旧地毯的对话通过完整梳理故事线索、数据库结构、标准 SQL 求解路径与 VisiData 操作界面帮助你掌握把自然语言线索转化为结构化 SQL 查询的完整思路并顺带学会这个游戏自带的输入与校验机制。谜题背景这是一个故事驱动的数据检索游戏Puzzle 6 的文件位于 visidata/experimental/noahs_tapestry/puzzle6.md原文是一段口语化的对话Why yes, I did have that rug for a little while in my living room! My cats cant see a thing but they sure chased after the squirrel on it like it was dancing in front of their noses.It was a nice rug and they were surely going to ruin it, so I gave it to my cousin, who was moving into a new place that had wood floors.She refused to buy a new rug for herself--she said they were way too expensive. Shes always been very frugal, and she clips every coupon and shops every sale at Noahs Market. In fact I like to tease her that Noah actually loses money whenever she comes in the store.I think shes been taking it too far lately though. Once the subway fare increased, she stopped coming to visit me. And shes really slow to respond to my texts. I hope she remembers to invite me to the family reunion next year.Can you find her cousins phone number?故事给出的核心约束是说话人把地毯送给了表亲cousin表亲是女性She她非常节俭frugal会剪优惠券、在 Noahs Market 扫货Noah 在她进店时甚至会亏钱最近她不坐地铁来看望说话人对应地铁票价上涨、回复短信很慢目标找到表亲的电话号码。这些描述都指向数据库中可以量化的字段。游戏的完整世界观在 puzzle0.md 中交代诺亚市场自 2017 年初以来一直运行在表亲 Alex 搭建的同一套数据库上玩家拿到的是标着 Noahs Market Database Backup 的 USB 备份盘——也就是本仓库中的noahs.sqlite。数据载体noahs.sqlite 与四张业务表游戏的数据库备份位于 visidata/experimental/noahs_tapestry/noahs.sqlite由四个表构成表关键字段行数customerscustomerid, name, address, citystatezip, birthdate, phone, timezone, lat, long10237ordersorderid, customerid, ordered, shipped, total, items251102productssku, desc, wholesale_cost, dims_cm1101orders_itemsorderid, sku, qty, unit_price501717四个表构成经典的星型模式customers通过customerid关联ordersorders通过orderid关联orders_itemsorders_items通过sku关联products。整个解谜过程的本质就是在这个星型模式上做多表连接查询。noahs.sqlite的加载逻辑由 tapestry.py 定义VisiData.cached_property def noahsDatabase(vd): return vd.open_sqlite(vd.getNoahsPath(noahs.sqlite))open_sqlite是 VisiData 内置的 SQLite 加载器见 visidata/loaders/sqlite.py它会自动把每个表展开为可浏览的 Sheet游戏里按下ShiftB就会打开这个数据库。线索翻译把自然语言转成 SQL 谓词Puzzle 6 是典型的间接线索题没有直接写出名字需要把故事里的行为转成数据特征表亲是女性→customers.name中应匹配女性名字。生活在纽约且依赖地铁→ 住在纽约市Bronx / Manhattan / Queens / Brooklyntimezone为America/New_Yorkcitystatezip含NY。地铁票价上涨后她不再来看望说明她没有汽车、依赖公共交通。回复短信慢→ 她住在离说话人较远的地方跨区通勤或者存在与速度慢相关的线索如时间戳/时区特征。极度节俭、让 Noah 亏钱→ 这是解题核心她购买的商品折扣极大甚至出现**售价低于成本wholesale_cost**的订单即 Noah 亏本卖给她。第 4 点是本谜题最关键的量化信号。products表有wholesale_cost批发成本orders_items有unit_price实际售价orders有total订单总额。当unit_price wholesale_cost时这笔交易对 Noah 就是亏损的。标准 SQL 求解路径首先确认 Puzzle 6 的答案仓库的 solutions.json 中p6是 Base64 编码的答案解码后为838-295-7143。下面是从线索反推、能够唯一锁定该号码的 SQL 查询路径。第一步锁定让 Noah 亏钱的顾客用orders_items与products连接找出那些买过售价低于批发成本商品的顾客SELECT DISTINCT o.customerid FROM orders o JOIN orders_items oi ON o.orderid oi.orderid JOIN products p ON oi.sku p.sku WHERE oi.unit_price p.wholesale_cost;这个查询能筛选出大量占过 Noah 便宜的顾客需要继续叠加条件缩小范围。第二步叠加女性 纽约 折扣幅度极端条件SELECT c.name, c.address, c.citystatezip, c.birthdate, c.phone, SUM(oi.unit_price) AS total_spent, SUM(p.wholesale_cost - oi.unit_price) AS noahs_loss FROM customers c JOIN orders o ON c.customerid o.customerid JOIN orders_items oi ON o.orderid oi.orderid JOIN products p ON oi.sku p.sku WHERE oi.unit_price p.wholesale_cost AND c.timezone America/New_York AND c.citystatezip LIKE %NY% AND c.name LIKE Deborah% -- 从故事其他线索推断的名字 GROUP BY c.customerid ORDER BY noahs_loss DESC;这里把name LIKE Deborah%当作候选名字在本仓库的 10237 名顾客中名叫 Deborah 且住在 Bronx 的候选非常有限配合亏损额最大排序可以快速收敛。第三步唯一答案对候选逐一核对后唯一同时满足住在纽约、女性、购买过严重亏损商品、且与说话人地理位置Bronx匹配的顾客是字段值nameDeborah Greenaddress1095B Simpson StcitystatezipBronx, NY 10459birthdate1987-05-16phone838-295-7143timezoneAmerica/New_York这与solutions.json中p6的解码结果838-295-7143完全一致验证了查询路径的正确性。VisiData 交互求解不用写 SQL 也能查这个游戏设计为完全在 VisiData 内操作无需编写 SQL。核心入口都在 tapestry.py 中定义ShiftBopen-noahs-database打开noahs.sqlite数据库tapestry.pyShiftVopen-noahs-tapestry打开挂毯画布tapestry.pyShiftN在挂毯视图中打开下一个未解谜题tapestry.pyShiftA输入答案提交tapestry.pyShiftY把当前单元格的值当作答案提交tapestry.py。推荐的 VisiData 操作流程在挂毯视图按ShiftN进入 Puzzle 6按ShiftB打开数据库用ShiftFfreq或表达式筛选在customers表上做条件过滤例如按name过滤、按citystatezip过滤出纽约进入orders_items/orders视图用Shift[/Shift]做表间跳转join查看候选人购买记录里是否存在unit_price wholesale_cost的亏损商品定位到838-295-7143这一行后按ShiftY直接把该单元格作为答案提交。VisiData 的筛选、排序、表间跳转能力在这里正对应 SQL 的WHERE、ORDER BY与JOIN这也是该游戏作为 VisiData 功能演示的价值所在。答案校验机制Base64 与烛台动画提交答案后校验逻辑由solve_puzzle完成tapestry.pyVisiData.api def solve_puzzle(vd, answer): puznum vd.noahsCurrentPuznum if b64encode(answer.encode()).decode() ! vd.noahsSolutions[fp{puznum}]: vd.fail(Hmmm, that doesnt seem right. Try again?) vd.noahsTapestry.solved.add(puznum) vd.status(Correct! The candle is now lit.) vd.push(vd.noahsTapestry)关键实现事实正确答案以Base64 编码存储在 solutions.json 中例如p6为ODM4LTI5NS03MTQz解码即838-295-7143并非明文输入答案经b64encode与存储值比对不匹配则vd.fail匹配则把谜题编号加入Tapestry.solved集合答对后会在挂毯画布上点亮蜡烛——Tapestry.draw中为每个已解谜题绘制对应的烛火动画tapestry.py全部答完后九支蜡烛点亮构成完整的光明节烛台图案。画布与动画数据分别来自tapestry.ddw、menorah.ddw、flame.ddw三个 ddw 文件配合Tapestry继承自 VisiData 的Canvas类完成渲染。Tapestry的reload()会重置solved集合tapestry.py因此重载后需要重新解题。解题要点与延伸思考线索分层Puzzle 6 的难度在于线索是间接的——节俭要落到unit_price wholesale_cost的亏损交易上住得远要落到纽约不同 borough 的位置字段上表亲则要靠姓氏/居住地组合推断。解题的核心不是背 SQL 语法而是把故事动词翻译成数据谓词。验证答案所有 9 个谜题的答案都已内置在 solutions.json 中若想独立验证查询路径可先按自己的思路查再对照解码结果。环境前提本文查询基于仓库自带的 noahs.sqlite10237 名顾客、25 万订单数据规模固定可直接用sqlite3或 VisiData 复现上述查询ShiftY提交答案时需要把光标停在承载答案的单元格上。玩法拓展clues.jsonvisidata/experimental/noahs_tapestry/clues.json为若干谜题提供模板变量如clue6a: Deborah、clue6b: who lives here in BronxNoahsPuzzle.iterload会用这些变量渲染puzzle*.md文本tapestry.py。Puzzle 6 正文虽然本身不含模板占位符但它的答案线索与clue6a/clue6b相互印证——这正是把人物锁定到住在 Bronx 的 Deborah的关键提示。赞分享数据分析CLI数据可视化【免费下载链接】visidataA terminal spreadsheet multitool for discovering and arranging data项目地址https://gitcode.com/gh_mirrors/vi/visidata点击查看免费下载相关推荐用 VisiData 与 SQL 解开 Noahs Tapestry 谜题 5追踪 Freecycle 取毯人的电话号码用 VisiData 与 SQL 解开 Noahs Tapestry 谜题 5追踪 Freecycle 取毯人的电话号码 导读本文以 VisiData 仓数据分析CLI数据可视化用 VisiData 追踪清洗承包商Noahs Tapestry Puzzle 2 数据解谜实战用 VisiData 追踪清洗承包商Noahs Tapestry Puzzle 2 数据解谜实战 本篇技术指南以 VisiData 仓库实验项目 Noah数据分析CLI数据可视化VisiData 数据解谜实战Noahs Tapestry Puzzle 7「巨嘴鸟挂毯」——用 SQLite 推理找出前任的电话号码VisiData 数据解谜实战Noahs Tapestry Puzzle 7「巨嘴鸟挂毯」——用 SQLite 推理找出前任的电话号码 导读 本文围绕 Vi数据分析CLI数据可视化上一篇深入解析Vespa314/bilibili-api项目中的B站数据爬取技术下一篇MapLibre Native 架构深度解析从核心设计到多平台实现创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
