Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#generate-yql').on('click', function() {
- const estimation = $('#estimation').val();
- const yt_path = $('#yt_path').val();
- if (!estimation || !yt_path) {
- toastr.error("Нужно выбрать тип разметки и yt таблицу");
- return;
- }
- let yql = ""
- yql += "USE hahn;\n"
- yql += "\n"
- yql += "SELECT *\n"
- yql += "FROM `" + yt_path + "`"
- // Создаём фильтры для YQL запроса.
- // На выходе получаем строку вида (<right><value><left> OR <right><value2><left>)
- // Например:
- // * (result = 'correct' OR result = 'not_correct')
- // * (Yson::LookupBool(beauty_result, 'bad_picture') OR Yson::LookupBool(beauty_result, 'bad_structure'))
- const generate_filters = (right, values, left) => {
- if (Array.isArray(values) && values.length > 0) {
- return " (" + values.map(value => right + value + left).join(" OR ") + ")"
- }
- }
- const filters = [
- generate_filters("cnt ", $("#users").val(), ""),
- generate_filters("result = '", $("#results").val(), "'"),
- generate_filters("platform = '", $("#platforms").val(), "'"),
- generate_filters("tld = '", $("#domains").val(), "'"),
- generate_filters("sources = '", $("#sources").val(), "'"),
- generate_filters("is_extended_factcheck = ", $("#factchecks").val(), ""),
- generate_filters("Yson::LookupBool(beauty_result, '", $("#beauty_results").val(), "')"),
- ].filter(x => x); // Удаляем null элементы
- if (filters.length > 0) {
- yql += "\nWHERE\n"
- yql += filters.join("\n AND\n")
- }
- $('#modal').modal('show');
- $("#yql").val(yql);
- resize_textarea();
- });
Advertisement