Why is my SQL Server CASE statement not working as expected [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I am trying to align these classifications using a CASE statement but the table build is still returning an incorrect value for the 3rd column in row 2 of the results (below). Can you help me figure out why? -- I'm really scratching my head here?
Code and screenshot below:
image highlighting the problem
SELECT DISTINCT
dom_id = 5,
stg1.PVDESC,
'bus_segment_test' =
CASE
WHEN stg1.PVDESC LIKE '%Process Monitoring%'
THEN stg1.PVDESC
ELSE 'Environmental Monitoring'
END,
comm_bus_segment_test =
CASE
WHEN 'bus_segment_test' LIKE '%Process Monitoring%'
THEN 'Process Monitoring'
ELSE 'Environmental Monitoring'
END
FROM
CDW_Staging.dbo.STG_1_ERP0005_BILL AS stg1
Row 2 in the following output table shows the undesired results (because incorrectly showing 'Environmental Monitoring' in Col3 when it should say 'Process Monitoring'):
dom_id
PVDESC
bus_segment_test
comm_bus_segment_test
5
BioAerosol
Environmental Monitoring
Environmental Monitoring
5
Process Monitoring
Process Monitoring
Environmental Monitoring
5
Franklin Systems
Environmental Monitoring
Environmental Monitoring
5
Franklin
Environmental Monitoring
Environmental Monitoring
5
West Columbia
Environmental Monitoring
Environmental Monitoring
5
Coal
Environmental Monitoring
Environmental Monitoring

Your second CASE statement is comparing the string 'bus_segment_test' to '%Process Monitoring%'. I'd change WHEN 'bus_segment_test' LIKE '%Process Monitoring%' THEN 'Process Monitoring' to WHEN stg1.PVDESC LIKE '%Process Monitoring%' THEN 'Process Monitoring'

Related

Send notifications in telegram group [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
How can I have my telegramBot send automatically messages in a group?
def handle_event(event):
#print(event)
global amount0In
global amount1Out
global amount1In
global amount0Out
amount0In = event['args']['amount0In']
amount1Out = event['args']['amount1Out']
amount1In = event['args']['amount1In']
amount0Out = event['args']['amount0Out']
if amount0In and amount1Out != 0:
print(f"Token Sold {amount0In /10**18}, and eth {amount1Out/10**18}")
buy()
else:
print(f"Token Bought {amount0Out /10**18}, and eth {amount1In/10**18}")
sell()
def buy(update,context):
buyMessage = f"Buy!!!!\n💴: {amount1In/10**18}\nToken Bought: {amount0Out /10**18} \n"
update.message.reply_text(buyMessage)
def sell(update, context):
sellMessage = f"Sell!!!!\n💴: {amount1In/10**18}\nToken Sold: {amount0Out /10**18} \n"
update.message.reply_text(sellMessage)
In case the IF statement is met I want to send a message to a telgram group, however I cant execute the update message this way, because I keep getting this error:
TypeError: buy() missing 2 required positional arguments: 'update' and 'context'
How can I fix this?
To send a message, all you need is an instance of telegram.Bot. Please have a look at the introduction to the API for more details.
The functions buy and sell look like callback functions for handler. Since you are apparently not using python-telegram-bots handler setup to handle the event, there is no sense in defining those functions to accept the update and context arguments.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

0 and 1 - Switch Coverage in State Transition Testing?

This question is not programming related but related to one of test case design the technique. State Transition Diagram technique provides Test coverage by identifying test conditions via N-1 switch transitions.
I am confused about how to calculate the 0-switch and 1-switch coverage.
Adding screenshot of an example. Can anyone please explain how this can be solved?
Thank you in Advance.
The number of 0-switch from a state equals to the number of the transitions of length 1 starting from that state. In this case you have:
ACT-ACT;
ACT-ACC;
ACT-DIS;
ACT-CLO.
So, from Activated there are 4 transitions of length 1.
1-switch coverage from a state equals to all the transitions of length 2 starting from that state. You can build up from what you found in the 0-switch case, knowing which states you can reach from Activated in 1 transition. Just compute all the 0-switch transitions from each of these 4 states:
ACT: (as computed earlier) ACT-ACT; ACT-ACC; ACT-DIS; ACT-CLO -> 4;
ACC: ACC-ACT; ACC-CLO -> 2;
DIS: DIS-ACT; DIS-CLO -> 2;
CLO: CLO-DIS; CLO-ACT; CLO-REM; CLO-ACC -> 4.
In total, there are 12 1-STs.
But this is without considering the constraints in the second part of the exercise description.
"If a claim in state Accepted has been Closed it can only
be restored to the same state Accepted." -> it does not matter for the exercise, since we start from the state Activated.
"If a claim in state Activated has been Closed it can only be
restored to state Activated." -> this constraint rules out ACT-CLO-ACC.
So, in the end, you have 11 valid 1-STs.
There are 4 0-Switch transitions (states that you can reach with 1 leap from the Activated status):
Activated
Accepted
Disputed
Closed
There are 12 1-Switch transitions (states that you can reach with 2 leaps from the Activated status), however only 10 of them are valid:
Activated - Activated
Activated - Accepted
Activated - Disputed
Activated - Closed
Accepted - Activated
Accepted - Closed
Disputed - Activated
Disputed - Closed
Closed - Activated
Closed - Removed
The final restriction indicates that only Closed - Activated can be done, so Closed - Disputed, and Closed - Accepted do not count.
Addendum for Marco answer<<
Total solution for 1-switch is 9.
You rule out
ACT-CLO-ACC (as Marco said due to second restriction)
but You also rule out
ACT-CLO-REM (This one nobody excluded)
ACT-CLO-DIS (as Afner noted)

PLC or device to simulate switchgear in High Voltage substation

I need a simple and cheap "PLC" or another device to execute very simple task based on hardware input and outputs.
The goal is to simulate "switchgear" in a high voltage power substation, breakers and disconnectors.
Basicly it gives feedback of the device when in "open or closed state" based on "open and close commands" given
There are 7 devices in a bay, so there should be:
14 inputs for commands (7 open and 7 close commands)
14 outputs for states (7 open and 7 closed states)
The hardware input and outputs should handle 220V DC.
A small monitor or LEDs to show the states would be preferable.
I know this can be done with "simple relay technique", but the relays I can find capable for this are pretty expensive and pretty huge.
I also know it can be done by programming, and here is the basic idea of the code:
Variable_A = 0 'There should be 7 variables, so a copy of the entire code with variables A to G
If Hardware-input 1 'open command
Set Var_A: 0
delay 2s 'delay to
Set Var_A: 1
If Hardware-input 2 'close command
Set Var_A: 0
delay 2s
Set Var_A: 2
Case
Var_A = 0 'between state
Hardware-output1 = 0
Hardware-output2 = 0
Var_A = 1 'open state
Hardware-output1 = 0
Hardware-output2 = 1
Var_A = 2 'closed state
Hardware-output1 = 1
Hardware-output2 = 0
Var_A = 3 'illigal state
Hardware-output1 = 1
Hardware-output2 = 1
What I thought of is a Siemens DIN-rail PLC or a raspberry PI with external inputs/outputs.
So Im asking if anyone can recommend a good solution to this?
I was suggested Arduino and this seems like a perfect solution.
I believe you should ask this question in the Electrical Engineering Stack Exchange.
220VDC would be very unusual for a PLC.A common PLC with 24VDC Input and output will be a cheaper option.To use conventional 24VDC PLC I/O, you could place solid state relays or opto-couplers between the field devices and the PLC.

Rails SQL insert statements not showing up in console [duplicate]

This question already has answers here:
How to show SQL queries run in the Rails console?
(8 answers)
Closed 8 years ago.
My terminal used to display SQL table insert statements (as it should by default), and now it doesn't. Everything else - for example, GET requests, or local server startup info, or job completion notifications - appear as normal.
For the life of me, I can't figure out what the problem could be. I've been searching for a long time and can't figure out any reason this would happen. Do you have any ideas to point me in the right direction?
Put this in either in your .irbrc or .pryrc in your home directory
if defined?(Rails) && !Rails.env.nil?
puts '... ActiveRecord and ActiveResource Logger set to STDOUT'
logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = logger
ActiveResource::Base.logger = logger
end
You should start to see the sql statements executing in the rails console.
Hope this helps

Issue tracking system for an hospital? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've a friend working in an hospital and he asked for an issue tracking system.
Currently they are using only mails. I thought to Jira or Trac, but they use
"programming terms" like "bug" or "patch".
I don't want to spend time customizing, do you know any better solution/software?
I used Trac to implement issue tracking for managing the operations of a building. It is quite configurable, so I was able to conceal the software-bug-oriented wording without a lot of effort, though the admin interface.
I applied a trivial patch to Trac so that it displays boolean values as Y and N rather than the the "computerese" 1 and 0, and also, so that the false value is displayed a blank. (This is better in a columnar report where you have boolean columns, and you just want to clearly see where the Y values are; they are harder to see in a grid of Y's and N's).
Here it is below. Everything else, I did easily through the admin interface.
Index: pyshared/trac/ticket/web_ui.py
===================================================================
--- pyshared.orig/trac/ticket/web_ui.py 2011-09-16 11:59:40.000000000 -0700
+++ pyshared/trac/ticket/web_ui.py 2011-09-16 12:11:31.000000000 -0700
## -1120,7 +1120,7 ##
elif type_ == 'checkbox':
value = ticket.values.get(name)
if value in ('1', '0'):
- field['rendered'] = value == '1' and _('yes') or _('no')
+ field['rendered'] = value == '1' and 'yes' or ''
# ensure sane defaults
field.setdefault('optional', False)
Index: pyshared/trac/ticket/query.py
===================================================================
--- pyshared.orig/trac/ticket/query.py 2011-09-16 14:36:51.000000000 -0700
+++ pyshared/trac/ticket/query.py 2011-09-16 14:37:10.000000000 -0700
## -294,9 +294,9 ##
val = datetime.fromtimestamp(int(val or 0), utc)
elif field and field['type'] == 'checkbox':
try:
- val = bool(int(val))
+ val = val == '1' and 'Y' or ''
except TypeError, ValueError:
- val = False
+ val = ''
result[name] = val
results.append(result)
I know you said that you didn't want to time customizing, but I am afraid you are just out of luck on that. I doubt that there is any issue tracking system out there that will give you exactly what you want without customizing (or without exorbitant fees). So I will still recommend JIRA.
JIRA is incredibly customizable. We use it in our organization for tracking issues of many types from software issue tracking, to Vehicle reservations, to building maintenance work order requests, purchase request, and more. We also have plans to customize it for our students (I work in a college) to be able to request assistance with registration, submit feedback, and more.
JIRA is incredibly robust and, once you get the hang of it, not terrible to configure. I won't lie. Configuring JIRA, at first, is a chore and can be difficult to get a handle on. But there is a great book from O'Reilly called Jira Administration that helped me understand it all much better. And it is quite a small book (187 pages or so), so it is not filled with a bunch of fluff. It is just great and useful information.
We use JIRA Dashboards, Issue type customizations, notification schemes, permission schemes, issue type security, custom workflows, custom screens and forms, plugins, the Web Service APIs, and more. It really is a fantastic system.