Gistrec

YQL Generator v2

Mar 31st, 2022
850
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. $('#generate-yql').on('click', function() {
  2.     const estimation = $('#estimation').val();
  3.     const yt_path = $('#yt_path').val();
  4.     if (!estimation || !yt_path) {
  5.         toastr.error("Нужно выбрать тип разметки и yt таблицу");
  6.         return;
  7.     }
  8.  
  9.     let yql = ""
  10.     yql += "USE hahn;\n"
  11.     yql += "\n"
  12.     yql += "SELECT *\n"
  13.     yql += "FROM `" + yt_path + "`"
  14.  
  15.     // Создаём фильтры для YQL запроса.
  16.     // На выходе получаем строку вида (<right><value><left> OR <right><value2><left>)
  17.     // Например:
  18.     //     * (result = 'correct' OR result = 'not_correct')
  19.     //     * (Yson::LookupBool(beauty_result, 'bad_picture') OR Yson::LookupBool(beauty_result, 'bad_structure'))
  20.     const generate_filters = (right, values, left) => {
  21.         if (Array.isArray(values) && values.length > 0) {
  22.             return "   (" + values.map(value => right + value + left).join(" OR ") + ")"
  23.         }
  24.     }
  25.     const filters = [
  26.         generate_filters("cnt ",         $("#users").val(),      ""),
  27.         generate_filters("result = '",   $("#results").val(),    "'"),
  28.         generate_filters("platform = '", $("#platforms").val(),  "'"),
  29.         generate_filters("tld = '",      $("#domains").val(),    "'"),
  30.         generate_filters("sources = '",  $("#sources").val(),           "'"),
  31.         generate_filters("is_extended_factcheck = ",          $("#factchecks").val(),       ""),
  32.         generate_filters("Yson::LookupBool(beauty_result, '", $("#beauty_results").val(), "')"),
  33.     ].filter(x => x); // Удаляем null элементы
  34.  
  35.     if (filters.length > 0) {
  36.         yql += "\nWHERE\n"
  37.         yql += filters.join("\n    AND\n")
  38.     }
  39.  
  40.     $('#modal').modal('show');
  41.     $("#yql").val(yql);
  42.     resize_textarea();
  43. });
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment