Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 brianf 1
@ECHO OFF
2
SETLOCAL ENABLEDELAYEDEXPANSION
3
REM ----------------------------------------------------------------------------------------------
4
REM Script: SOM_Dashboard_query.cmd
5
REM Created: 2011/11/01
6
REM Author: Brian Fergusson
7
REM Version: 1
8
REM Description:
9
REM This is the main script for extracting data for the Testing Statistics SOM Dashboard.
10
REM The result of each dashboard query is outputted to a csv file.
11
REM The queries are run for the previous month of data (Variable, date_code (set below), must be set to 1 for this mode).
12
REM ----------------------------------------------------------------------------------------------
13
 
14
SET DIR_INPUT=.\queries
15
SET DIR_OUTPUT=.\output
16
REM SET DIR_OUTPUT=\\auperanas01\Data\Transit\temp
17
 
18
 
19
REM Disable debug mode
20
SET DEBUG=N
21
SET SERVER_TD=AUPERAMTD01
22
SET SERVER_CQ=AUPERASQL05
23
SET SERVER_JR=AUPERASQL05
24
 
25
REM Versions of each query (for debugging)
26
SET VER_TD=5
27
SET VER_JR=3
28
SET VER_CQ=8
29
 
30
PUSHD .
31
 
32
ECHO.
33
ECHO Test Director Server: %SERVER_TD%
34
ECHO Clear Quest Server:   %SERVER_CQ%
35
ECHO Jira Server:          %SERVER_JR%
36
 
37
REM  get month.  This is for the csv filename
38
SET month_qry=SQLCMD -S%SERVER_TD% -E -Q "SET NOCOUNT ON; select rtrim(year(DATEADD(mm,-1,CURRENT_TIMESTAMP))) + '_' + right('0' + rtrim(month(DATEADD(mm,-1,CURRENT_TIMESTAMP))),2)" -h-1 -s"," -W
39
FOR /f "usebackq tokens=1,2 delims=_" %%A IN (`%month_qry%`) DO (
40
  SET year=%%A
41
  SET month=%%B
42
)
43
 
44
ECHO Query Month:          %year%/%month%
45
 
46
ECHO.
47
ECHO Running SOM Dashboard queries for Month: %year%/%month%
48
ECHO.
49
 
50
REM  query previous month
51
REM date_code is accessed in the sql script
52
SET date_code=1
53
CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_TD.csv" "Test Director" "-E"
54
CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_CQ.csv" "Clear Quest"   "-E" 
55
CALL :query_to_csv %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_%year%%month%_JR.csv" "Jira"          "-E" 
56
 
57
IF %DEBUG% == Y (
58
  REM  This block of code is used for debugging purposes.
59
  REM  It is not required in a live system, ie SET DEBUG=N
60
 
61
  REM  Query data since 2009
62
  SET date_code=2
63
  CALL :query_to_csv %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_v%VER_TD%.csv" "Test Director" "-E"
64
  CALL :query_to_csv %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_v%VER_CQ%.csv" "Clear Quest"   "-E"
65
  CALL :query_to_csv %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_JR_DEVI_v%VER_JR%.csv" "Jira"          "-E"
66
 
67
  REM  generate row data for issue investigation purposes
68
  REM  query data for a specific debug date range, See Dashboard_query_init.sql
69
  SET date_code=3
70
  CALL :query_to_csv  %SERVER_TD% "%DIR_INPUT%\SOM_Dashboard_query_TD_TEST_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_TD_TEST_rows_aug_to_oct_v%VER_TD%.csv" "Test Director" "-E"
71
  CALL :query_to_csv  %SERVER_CQ% "%DIR_INPUT%\SOM_Dashboard_query_CQ_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_CQ_DEVI_rows_aug_to_oct_v%VER_CQ%.csv" "Clear Quest"   "-E"
72
  CALL :query_to_csv  %SERVER_JR% "%DIR_INPUT%\SOM_Dashboard_query_JR_DEVI_rows_aug_to_oct.sql" "%DIR_OUTPUT%\SOM_Dashboard_Test_JR_DEVI_rows_aug_to_oct_v%VER_JR%.csv" "Jira"          "-E"
73
)
74
 
75
 
76
ECHO.
77
ECHO Completed SOM Dashboard queries for Month: %year%/%month%
78
ECHO.
79
goto end
80
 
81
REM ----------------------------------------------------------------------------------------------
82
: query_to_csv
83
REM  Runs SQLCMD to run the specified query and output the result to the specified output file.
84
REM 
85
REM 
86
 
87
REM Note: %~1: removes surrounding quotes on parameter %1
88
SET server=%1
89
SET inpfile=%~2
90
SET outfile=%~3
91
SET datatitle=%~4
92
SET login=%~5
93
 
94
ECHO   Querying %datatitle% databases...
95
ECHO   Running %inpfile%
96
ECHO   Outputting to:%outfile%
97
 
98
REM outsputs to csv using a comma separater (-s",") and includes a header and no trailing spaces (-W).  Note: to remove headers use (-h-1)
99
REM Run sqlcmd and remove dashed line after the column header
100
 
101
SQLCMD -S%server% %login% -i "%inpfile%" -o "%outfile%" -s"," -W
102
REM   SQLCMD -S%server% %login% -i "%inpfile%" -s"," -W | find /v "-----" > "%outfile%"
103
 
104
ECHO   Completed querying %datatitle% databases.
105
ECHO.
106
GOTO endp
107
REM ----------------------------------------------------------------------------------------------
108
 
109
 
110
:end
111
POPD
112
REM pause
113
:endp