Django-PostgresPool max poolsize - django

Here is my setting :
DATABASE_POOL_ARGS = {
'max_overflow': 3,
'pool_size': 3,
'recycle': 300
}
I set pool_size =3
But I look up the result in postgres( SELECT sum(numbackends) FROM pg_stat_database; )
The number still over 3 , How can I set the connection ??
I want to set the max to 100,And let all requests share these 100 connections to communicate with postgresql

pool_size is the number of idle connections (ie at least these many will always be connected), and max_overflow is the maximum allowed on top of that.
So the total maximum is pool_size + max_overflow. You should set pool_size to the minimum number you think you will typically need, and max_overflow to 100 - pool_size.

Related

Pinescript - Syntax error at input 'else'

I am having an issue with pinescript. Never used it before and havent coded in years so im very rusty.
I would love an opinion of why I am getting the error on line 21, which is the only 'else if' line in the block.
//#version=4
tradeDirection = input(direction.up, "Trade Direction") // direction of the breakout (up or down)
breakoutPeriod = input(14, "Breakout Period") // number of bars to look back for the breakout
stopLoss = input(0.002, "Stop Loss") // stop loss in percentage of the trade value
takeProfit = input(0.004, "Take Profit") // take profit in percentage of the trade value
maxTrades = input(2, "Maximum Number of Trades") // maximum number of trades to have open at the same time
maxRisk = input(0.01, "Maximum Risk per Trade") // maximum risk per trade in percentage of the account value
// Next, we create a variable to track the highest or lowest price in the breakout period
breakoutPrice = tradeDirection == direction.up ? highest(high, breakoutPeriod) : lowest(low, breakoutPeriod)
// Then, we check if the current price has broken out of the breakout period and if we have not reached the maximum number of open trades
if (tradeDirection == direction.up and close > breakoutPrice and strategy.opentrades < maxTrades)
// If it has, we calculate the trade size based on the maximum risk per trade
tradeSize = maxRisk / (stopLoss * close)
// And enter a long position with the calculated trade size
strategy.entry("Long", strategy.long, tradeSize)
else if (tradeDirection == direction.down and close < breakoutPrice and strategy.opentrades < maxTrades)
// If it has, we calculate the trade size based on the maximum risk per trade
tradeSize = maxRisk / (stopLoss * close)
// And enter a short position with the calculated trade size
strategy.entry("Short", strategy.short, tradeSize)
// Finally, we set our stop loss and take profit levels
strategy.exit("Stop Loss", "Long", stopLossType.percent, stopLoss)
strategy.exit("Take Profit", "Long", profitType.percent, takeProfit)
// We repeat the same process for the short position
strategy.exit("Stop Loss", "Short", stopLossType.percent, stopLoss)
strategy.exit("Take Profit", "Short", profitType.percent, takeProfit)
I've looked around at other versions to see if its just a version issue but nothing that gives me a reaosn why its erroring out.
I get the feeling its something before or within the else if statement.
I retyped your script so it would compile and have no warnings or errors. One problem was the indentation was missing on the if and else. Another problem was the direction.up variable was missing. It is not allowed to have a . in a variable name. Another problem was that strategy("breakout strat") was missing, so I added it. The logic in the code I typed is probably wrong, but there are no errors.
//#version=4
strategy("breakout strat")
tradeDirection = input(true, "Trade Direction") // direction of the breakout (up=true or down=false)
breakoutPeriod = input(14, "Breakout Period") // number of bars to look back for the breakout
stopLoss = input(0.002, "Stop Loss") // stop loss in percentage of the trade value
takeProfit = input(0.004, "Take Profit") // take profit in percentage of the trade value
maxTrades = input(2, "Maximum Number of Trades") // maximum number of trades to have open at the same time
maxRisk = input(0.01, "Maximum Risk per Trade") // maximum risk per trade in percentage of the account value
// Next, we create a variable to track the highest or lowest price in the breakout period
breakoutPrice = tradeDirection == true ? highest(high, breakoutPeriod) : lowest(low, breakoutPeriod)
// Then, we check if the current price has broken out of the breakout period and if we have not reached the maximum number of open trades
if (tradeDirection == true and close > breakoutPrice and strategy.opentrades < maxTrades)
// If it has, we calculate the trade size based on the maximum risk per trade
tradeSize = maxRisk / (stopLoss * close)
// And enter a long position with the calculated trade size
strategy.entry("Long", strategy.long, tradeSize)
else if (tradeDirection == false and close < breakoutPrice and strategy.opentrades < maxTrades)
// If it has, we calculate the trade size based on the maximum risk per trade
tradeSize = maxRisk / (stopLoss * close)
// And enter a short position with the calculated trade size
strategy.entry("Short", strategy.short, tradeSize)
// Finally, we set our stop loss and take profit levels
strategy.exit("Stop Loss", "Long", loss=stopLoss)
strategy.exit("Take Profit", "Long", loss=takeProfit)
// We repeat the same process for the short position
strategy.exit("Stop Loss", "Short", loss=stopLoss)
strategy.exit("Take Profit", "Short", loss=takeProfit)
Put an indentation on line 21 to get rid of this error :
if .....
----> First block
else if
----> Other block
In your code other indentations are missing, and other error are present (direction.up doesn't exist for example... but you should ask another question for another error)

Scheduling Problem - solver does not see an obvious solution

The problem consists of a set of tasks requiring some resource from renewable resource pool.
The goal is to complete all tasks in the given planning horizon, so that
the number of resource used is minimised.
The main constraint is no overlap of tasks for the same resource.
The code below does not scale well if I increase the number of tasks.
There should be a simple optimal solution: to allocate the resource 1 to 15 to all tasks. But the solver seems to struggle to find it when n_tasks is higher than say 1000. I have tried a number of things with the search annotations, but no breakthrough so far.
Here is the model and data:
n_tasks = 3000;
duration = [1 | i in 1..n_tasks];
n_resources = 35;
number_resource_needed = [15 | i in 1..n_tasks];
t_max = 18000;
include "cumulative.mzn";
%-----------------------------------------------------------------------------%
% MODEL PARAMETERS
% Tasks
int: n_tasks; % The number of tasks
set of int: Tasks = 1..n_tasks; % The set of all tasks
array[Tasks] of int : duration ; % The task durations
% Resources
int: n_resources;
set of int: Resources = 1..n_resources;
array[Tasks] of int: number_resource_needed; % The resource requirements
% Maximum duration
int: t_max;
%~~~~~~~~~~~~~~~~~
% MODEL VARIABLES.
%~~~~~~~~~~~~~~~~~
array [Tasks] of var 1..t_max: start; % The start times
array[Tasks, Resources] of var 0..1: resource_allocation; %Selection of resources per task.
%~~~~~~~~~~~~~~~~~
% CONSTRAINTS
%~~~~~~~~~~~~~~~~~
% Number of Resources per Task constraint
constraint forall(t in Tasks) (
sum(r in Resources) (resource_allocation[t, r]) = number_resource_needed[t]
);
% Constraint allocated to only one task at a time
constraint forall(r in Resources)(
cumulative(start, duration, [resource_allocation[t, r] | t in Tasks], 1)
);
var int: objective = sum(r in Resources) (r * max([resource_allocation[t, r] | t in Tasks]));
var int: nb_active_workers = sum(r in Resources) (max([resource_allocation[t, r] | t in Tasks]));
% solve minimize objective;
solve :: seq_search([
int_search(resource_allocation, input_order, indomain_max),
int_search(start, input_order, indomain_min),
])
minimize objective;
output ["objective = \(objective) \n"];
output ["nb_active_workers = \(nb_active_workers) \n"];
I have used Chuffed, and different options.
My results:
n_tasks = 100, optimal found in 34s
n_tasks = 500, optimal found in 3m 43s
n_tasks = 3000, first solution 2m 40s, optimal not found at 4m 00s
I would like to see a first solution faster, and also the optimal faster.

How to request for more 100 device in wso2iot?

How to increase the offet and limit more than 100 ? At present we are unable to request more than 100 limit. Can you please help me ???
Pagination works like below;
- offset = 0, limit = 100 -> 0-100 devices
- offset = 101, limit = 100 -> 100-200 devices
- offset = 201, limit = 100 -> 200-300 devices
- ....continues....
As you can see above limit can be a positive integer(less than 100). Most of the time limit is constant, and we keep increasing the offset for the next API calls.
For example;
let offset = 0 limit = 100 when starting; you can do offset = offset + limit for the next call.
- https://192.168.1.18:8243/api/device-mgt/v1.0/devices?offset=0&limit=100
- https://192.168.1.18:8243/api/device-mgt/v1.0/devices?offset=101&limit=100
- https://192.168.1.18:8243/api/device-mgt/v1.0/devices?offset=201&limit=100

Calculate value using proportion

I'm designing a machine that requires an automated ignition system. This project uses a motor control script that I wrote for Arduino.
I need to calculate the delay between ignition based on the percentage motor load.
These are the variables currently used
//Variables
int potentiometerIn; //RAW Potentiometer data variable
int potentiometerIn2; //Used in percent calculation, Will be == to potentiometerIn, just a different operation order
int potentiometerDivper; //Variable to hold percentage calculation (first step)
int potentiometerPer; // Holds the integer percent for motor speed IE: motor at 83% speed would have this value at 83
int potentiometerDiv;
int motorPin = (); //REPLACE () with PIN NUM
int motorRly = (); //Motor Positive pin () = pin num + Motor Pin
int motorNeg = (); //Motor Negative Pin () = pin num (Likely Not Needed)
int igniteRly = (); //Ignition Control Positive Pin
int igniteNeg = (); //Ignition Control Negative Pin (Likely Not Needed)
int ignitionTime = 0; // This will be used to set the time for an electric ignition.
int ignitionCalc = (); //This should be the time in seconds, that it takes for the machine to complete a full cycle with the motor set to 50%
// This enables/disables the ignition portion
int ignitionEnabled = true; // Default = True
if (ignitionEnabled == true)
{
ignitionCalc * 1000; //Converts the seconds to a format accepted by delay
50 / ignitionCalc = potentiometerPer / ignitionTime;
}
A quick summary for those who don't want to read all of my comments (I'm writing this code before the motor arrives so the values are all unset)
potentiometerPer > This is the percentage of power being supplied to the motor.
ignitionTime > This value will be used to set the delay between ignition firing
ignitionCalc > The amount of time in seconds for 1 cycle at 50% power.
I'm trying to figure out a way to calculate the delay for ignition with regards to what percentage the motor is currently set to. For example:
If motor percentage is 80 and the time per cycle is 5, then at 100% power the time per cycle is X (in this case 6.25)
I can't seem to figure out how to do proportions in C++, I'm rather new to the language and only started to learn it for this project.
Well since when the motor power is at 80%, the time per cycle you get is 5. So ignore the percentage, lets just say that when power level is 80, you get time per cycle as 5. Ratios in simpler words are just divisions. When 80 is divided by 16, you get 5. So what we know is the value 16 is going to remain constant. Similarly if you take any value of motor power, and divide by 16, you are going to get what you want. If this ratio is going to remain constant then it will be for all cases no matter what the motor power is. Im assuming that the ratio is going to remain constant.
So what you can do is -
float timePerCycle = potentiometerPer/16;

What is rolling sum and how to impliment it in Informatica and my requirement is as follows?

Can someone pl tell me what is rolling sum and how to implement it in Informatica?
My requirement is as below:(Given by client)
ETI_DUR :
SUM(CASE WHEN AGENT_EXPNCD_DIM.EXCEPTION_CD='SYS/BLDG ISSUES ETI' THEN IEX_AGENT_DEXPN.SCD_DURATION ELSE 0 END)
ETI_30_DAY :
ROLLING SUM(CASE WHEN (SYSDATE-IEX_AGENT_DEXPN.ROW_DT)<=30 AND AGENT_EXPNCD_DIM.EXCEPTION_CD = 'SYS/BLDG ISSUES ETI'
THEN IEX_AGENT_DEXPN.SCD_DURATION ELSE 0 END)
ETI_30_DAY_OVRG :
CASE WHEN ETI_DUR > 0 THEN
CASe
WHEN ROLLINGSUM(ETI_DUR_30_DAY FOR LAST 29 DAYS) BETWEEN 0 AND 600 AND ROLLINGSUM(ETI_DUR_30_DAY FOR LAST 29 DAYS) + ETI_DUR > 600 THEN ROLLINGSUM(ETI_DUR_30_DAY FOR LAST 30 DAYS) - 600
WHEN ROLLINGSUM(ETI_DUR_30_DAY FOR LAST 29 DAYS) > 600 THEN ETI_DUR
ELSE 0 END
ELSE 0 END
And i have implemented as below in Informatica.
Expression Transformation:
o_ETI_DUR-- IIF(UPPER(EXCEPTION_CD_AGENT_EXPNDIM)='SYS/BLDG ISSUES ETI',SCD_DURATION,0)
o_ETI_29_DAY-- IIF(DATE_DIFF(TRUNC(SYSDATE),trunc(SCHD_DATE),'DD') <=29 AND UPPER(EXCEPTION_CD_AGENT_EXPNDIM) = 'SYS/BLDG ISSUES ETI' ,SCD_DURATION,0)
o_ETI_30_DAY -- IIF(DATE_DIFF(TRUNC(SYSDATE),trunc(SCHD_DATE),'DD') <=30 AND UPPER(EXCEPTION_CD_AGENT_EXPNDIM) = 'SYS/BLDG ISSUES ETI' ,SCD_DURATION,0)
Aggregator transformation:
o_ETI_30_DAY_OVRG:
IIF(sum(i_ETI_DUR) > 0,
IIF((sum(i_ETI_29_DAY)>=0 and sum(i_ETI_29_DAY)<=600) and (sum(i_ETI_29_DAY)+sum(i_ETI_DUR)) > 600,
sum(i_ETI_30_DAY) - 600,
IIF(sum(i_ETI_29_DAY)>600,sum(i_ETI_DUR),0)),0)
But is not working. Pl help ASAP.
Thanks a lot....!
Rolling sum is just the sum of some amount over a fixed duration of time. For example, everyday you can calculate the sum of expense for last 30 days.
I guess you can use an aggregator to calculate ETI_DUR, ETI_30_DAY and ETI_29_DAY. After that, in an expression you can implement the logic for ETI_30_DAY_OVRG. Note that you cannot write an IIF expression like that in an aggregator. Output ports must use an aggregate function.
Here is a rolling sum example:
count, rolling_sum
1,1
2,3
5,8
1,9
1,10
Basically it is the sum of the values listed previously. To implement it in Informatica use 'local variables' (variable port in expression transformation) as follows:
input port: count
variable port: v_sum_count = v_sum_count + count
output port: rolling_sum = v_sum_count
we have a moving sum function defined in Numerical functions in Expression transformation:
MOVINGSUM(n as numeric, i as integer, [where as expression]).
Please check if it helps.