【问题标题】:How to create dummy data for steps of a recipe?如何为配方步骤创建虚拟数据?
【发布时间】:2018-09-04 02:00:53
【问题描述】:

我正在创建一个膳食计划器 mysql 数据库应用程序。 为此,我需要将配方的说明分解为不同的步骤(这部分不可协商)

我需要用虚拟数据填充我的数据库。对于配方步骤(例如“将水混合成面糊”),获取虚拟数据的最佳方法是什么?

一个示例 python 脚本或网站会非常有用。

谢谢

【问题讨论】:

    标签: mysql database dummy-data


    【解决方案1】:

    不确定您是否仅限于使用 Python,但快速的 Google 搜索会弹出 https://github.com/joke2k/faker 作为库,以便在开发期间创建假数据。您也可以轻松编写自己的脚本来为您提供一些随机数据,特别是因为您需要将特定类型的字符串插入到数据库中。

    【讨论】:

      【解决方案2】:

      我也为此目的使用了一个 PHP 库,效果很好。 https://github.com/fzaninotto/Faker

      <?php
      // require the Faker autoloader
      require_once '/path/to/Faker/src/autoload.php';
      // alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)
      
      // use the factory to create a Faker\Generator instance
      $faker = Faker\Factory::create();
      
      // generate data by accessing properties
      echo $faker->name;
        // 'Lucy Cechtelar';
      echo $faker->address;
        // "426 Jordy Lodge
        // Cartwrightshire, SC 88120-6700"
      echo $faker->text;
        // Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit
        // et sit et mollitia sed.
        // Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium
        // sit minima sint.
      

      【讨论】:

      • 我主要看到它用于随机句子或一个单词,例如名字。您能否详细说明我如何使用faker?
      • 我在上面编辑了我的答案,向您展示如何将它用于您的项目,例如名称或填充文本。希望有帮助。还可以看看他们的文档,它非常直接且易于理解
      猜你喜欢
      • 2018-11-29
      • 2017-07-21
      • 1970-01-01
      • 2012-08-18
      • 2021-03-05
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      相关资源
      最近更新 更多