package io.renren.modules.sys.controller;

import io.renren.common.utils.R;
import io.renren.datasource.annotation.DataSource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理算法参数模板
 * @author Zhang
 * @version 3.0.0
 * @since JDK1.8
 */
@RestController
@RequestMapping("/getVisiTemplate")

public class VisiGetParaTempController {

//    @GetMapping("/pythonHbase")
//    public R pythonHbase(){
//        String hbaseStrnig="import happybase\n" +
//                "import time\n" +
//                "\n" +
//                "connection = happybase.Connection(host='10.170.15.57', port=9090)\n" +
//                "name=\"请在这里输入要创建的算法名称\"\n" +
//                "families={\n" +
//                "    \"data\":dict()\n" +
//                "}\n" +
//                "connection.create_table(name,families)\n" +
//                "#插入数据\n" +
//                "table = happybase.Table(name,connection)\n" +
//                "data={\"data:key\":\"value\"}#请在key,value处分别写出要存的键和值，如果要存多种信息，可通过逗号分隔\n" +
//                "table.put(str(int(time.time())),data)";
//        return R.ok().put("code",hbaseStrnig);
//    }

    /**
     * 输入输出文件模板示例
     * @return 示例
     */
    @GetMapping("/inoutputParaTemp")
    public R inoutputParaTemp(){
//        String paraTempString = "输入输出参数文件  代码模板";
        String paraTempString = "输入输出参数规范文件为.txt文本文件类型，具体格式如下\n" +
                "Input:\n" +
                "ParameterInput: 参数名称，参数类型，参数描述\n" +
                "FileInput: 参数名称，参数类型，参数描述\n" +
                "Output：\n" +
                "参数名称，参数类型，参数描述\n\n" +
                "ParameterOutput: 参数名称，参数类型，参数描述\n" +
                "FileOutput: 参数名称，参数类型，参数描述\n" +
                "其中 userInput 表示需要用户输入的参数值，例如KNN算法中的n_neighbors值; getInput表示需要应用其他组件产生的输出值来作为该参数的值，例如 \n\n"+
                "具体格式如下：\n"+
                "{\"Input\":{\"ParameterInput\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...],\"FileInput\":[{\"paraname\":\" \",\"parapath\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...]}," +
                "\"Output\":{\"ParameterOutput\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \",\"valuefrom\":\" \",},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \",\"valuefrom\":\" \",},...],\"FileOutput\":[{\"paraname\":\" \",\"parapath\":\" \",\"paradesc\":\" \",\"valuefrom\":\" \",},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \",\"valuefrom\":\" \",},...]}";
//                "{\"Input\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...],\"Output\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...]}";
//        输入输出文件模板示例

        String paraTempExamString = "{\"Input\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...],\"Output\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...]}";
        String paraTempExanString1 = "{\"Input\":{\"ParameterInput\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...],\"FileInput\":[{\"paraname\":\" \",\"parapath\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...]},\"Output\":[{\"paraname\":\" \",\"paratype\":\" \",\"paradesc\":\" \"},{\"paraname\":\"\",\"paratype\":\" \",\"paradesc\":\" \"},...]}";
        String hbaseStrnig="import happybase\n" +
                "import time\n" +
                "\n" +
                "connection = happybase.Connection(host='10.170.15.57', port=9090)\n" +
                "name=\"请在这里输入要创建的算法名称\"\n" +
                "families={\n" +
                "    \"data\":dict()\n" +
                "}\n" +
                "connection.create_table(name,families)\n" +
                "#插入数据\n" +
                "table = happybase.Table(name,connection)\n" +
                "data={\"data:key\":\"value\"}#请在key,value处分别写出要存的键和值，如果要存多种信息，可通过逗号分隔\n" +
                "table.put(str(int(time.time())),data)";
        return R.ok().put("code",paraTempString).put("paratempExamCode",paraTempExanString1);
    }

    /**
     * 20211112   输出文件模板相关
     * @return 输出文件模板
     */
    @GetMapping("/pythonOutputParaTemp")
    public R pythonParaTemp(){
        String paraTempString = "#!/usr/bin/python\n" +
                "# -*- coding:utf-8 -*-\n" +
                "import json\n" +
                "import inspect\n" +
                "\n" +
                "#  获取变量名   或者不用该方式 自输入名称实现完成\n" +
                "def retrieve_name(var):\n" +
                "    callers_local_vars = inspect.currentframe().f_back.f_locals.items()\n" +
                "    return [var_name for var_name, var_val in callers_local_vars if var_val is var]\n" +
                "\n" +
                "# 指定文件路径   当前路径？  或者文件系统的路径\n" +
                "file = open('paraOutputPara.txt','w')\n" +
                "\n" +
                "# 拼接参数  为字典; 每个参数包括  参数名称：参数值\n" +
                "\n" +
                "name, address, age, gender = \"bob\", \"hangzhou\", 21, \"man\"\n" +
                "parameters= {}\n" +
                "\n" +
                "\n" +
                "for i in [name, address, age, gender]:\n" +
                "    parameters[retrieve_name(i)[0]] = i\n" +
                "\n" +
                "file.write(json.dumps(parameters))";
        String paratempExapString = "{\"name\": \"bob\", \"address\": \"hangzhou\", \"age\": 21, \"gender\": \"man\"}";


        String hbaseStrnig="import happybase\n" +
                "import time\n" +
                "\n" +
                "connection = happybase.Connection(host='10.170.15.57', port=9090)\n" +
                "name=\"请在这里输入要创建的算法名称\"\n" +
                "families={\n" +
                "    \"data\":dict()\n" +
                "}\n" +
                "connection.create_table(name,families)\n" +
                "#插入数据\n" +
                "table = happybase.Table(name,connection)\n" +
                "data={\"data:key\":\"value\"}#请在key,value处分别写出要存的键和值，如果要存多种信息，可通过逗号分隔\n" +
                "table.put(str(int(time.time())),data)";
        return R.ok().put("code",paraTempString).put("outputParaExamCode",paratempExapString);
    }
}
