I want to check unassigned tickets in jira using java,python or any other script.
Using jira-python we first search for all the possible issues, then we check if the assignee field is None, thus nobody assigned.
# search_issues can only return 1000 issues, so if there are more we have to search again, thus startAt=count
issues = []
while True:
tmp_issues = jira_connection.search_issues('', startAt=count, maxResults=count + 999)
if len(tmp_issues) == 0:
# Since Python does not offer do-while, we have to break here.
break
issues.extend(tmp_issues)
count += 999
not_assigned = []
for i in issues:
if i.fields.assignee is None:
not_assigned.add(i)
Related
I am using python to insert *Include, Input=file.inp into step load definition section to apply for pressure boundary condition on nodes. Here is my script, however, it is inserted in Part level section. I am wondering how to control the insert position using python. Thanks
def GetKeywordPosition(myModel, blockPrefix, occurrence=1):
if blockPrefix == '':
return len(myModel.keywordBlock.sieBlocks)+1
pos = 0
foundCount = 0
for block in myModel.keywordBlock.sieBlocks:
if string.lower(block[0:len(blockPrefix)])==\
string.lower(blockPrefix):
foundCount = foundCount + 1
if foundCount >= occurrence:
return pos
pos=pos+1
return +1
position = GetKeywordPosition(myModel, '*step')+24
myModel.keywordBlock.synchVersions(storeNodesAndElements=False)
myModel.keywordBlock.insert(position, "\n*INCLUDE, INPUT=file.inp")
You can adapt the re module. This should work
import re
# Get keywordBlock object
kw_block = myModel.keywordBlock
kw_block.synchVersions(storeNodesAndElements=False)
sie_blocks = kw_block.sieBlocks
# Define keywords for the search (don't forget to exclude special symbols with '\')
kw_list = ['\*Step, name="My Step"']
# Find index
idx = 0
for kw in kw_list:
r = re.compile(kw)
full_str = filter(r.match, sie_blocks[idx:])[0]
idx += sie_blocks[idx:].index(full_str)
UPD: Some explanations as requested
As keywords in the .inp file could be somewhat repetitive, the main idea here is to create a "search route", where the last pattern in the list will correspond to a place where you want to make your modifications (for example, if you want to find the "*End" keyword after a specific "*Instance" keyword).
So we proceed iteratively through our "search route" == list of search patterns:
Compile the regex expression;
Find the first appearance of the pattern in the sie_blocks starting from the index idx;
Update the idx so the next search is performed from this point.
Hope this will help
I've used the following code to find a key word or phrase then highlight the line -- but can't figure out how to make it highlight the entire paragraph and/ or list that follows it...
For example:
(ideally, highlighting this paragraph AND the list that provides further details would be best -but if only the paragraph is achievable, that's better than nothing):
"The Contractor shall turn in monthly status reports within ten business days after the end of each month. The report should include:
(a) Accomplishments
(b) Meetings and Outcomes
(c) Completed Travel and Purpose of Travel"
I've researched several commands and looked for examples but still at a loss as a novice. I tried "wdParagraph" but couldn't get that to work. Located refs of maybe using a "paragraph.range.select" and also found a note that advised these "start" and "end" terms (below) to select a paragraph.. but not sure how to achieve this? Hoping someone has an example of how to accomplish this as it will help greatly with quickly identifying hundreds of software reqs out of a 100 page word doc.. so frustrated!
* Selection.StartOf Unit:=wdParagraphm
* Selection.MoveEnd Unit:=wdParagraph
Sub Find_Highlight_Word_to_End_of_Line()
'BUT NEED IT TO HIGHLIGHT THROUGH END OF PARAGRAPH
'AND HIGHLIGHT LISTED ITEMS IF APPLICABLE
'LIKE THE LISTS IN THE EXAMPLE DOCUMENT
Dim sFindText As String
'Start from the top of the document
Selection.HomeKey wdStory
sFindText = "Contractor Shall"
Selection.Find.Execute sFindText
Do Until Selection.Find.Found = False
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Range.HighlightColorIndex = wdYellow
Selection.MoveRight
Selection.Find.Execute
Loop
End Sub
A couple of awesome experts shared 2 methods with me to achieve the full paragraph highlighting I needed.. Hope these help others! Fascinating to see different ways to achieve the same result!
Method 2 Code (Alternative) is shorter:
Sub Highlight_Paragraph()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="Contractor Shall")
oRng.Paragraphs(1).Range.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Method 1 Code (MatchWildcards=False):
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Contractor Shall"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = False
.Execute
End With
Do While .Find.Found
.Duplicate.Paragraphs.First.Range.HighlightColorIndex = wdYellow
.Start = .Duplicate.Paragraphs.First.Range.End
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
I successfully wrote an intersection of text search and other criteria using Redis. To achieve that I'm using a Lua script. The issue is that I'm not only reading, but also writing values from that script. From Redis 3.2 it's possible to achieve that by calling redis.replicate_commands(), but not before 3.2.
Below is how I'm storing the values.
Names
> HSET product:name 'Cool product' 1
> HSET product:name 'Nice product' 2
Price
> ZADD product:price 49.90 1
> ZADD product:price 54.90 2
Then, to get all products that matches 'ice', for example, I call:
> HSCAN product:name 0 MATCH *ice*
However, since HSCAN uses a cursor, I have to call it multiple times to fetch all results. This is where I'm using a Lua script:
local cursor = 0
local fields = {}
local ids = {}
local key = 'product:name'
local value = '*' .. ARGV[1] .. '*'
repeat
local result = redis.call('HSCAN', key, cursor, 'MATCH', value)
cursor = tonumber(result[1])
fields = result[2]
for i, id in ipairs(fields) do
if i % 2 == 0 then
ids[#ids + 1] = id
end
end
until cursor == 0
return ids
Since it's not possible to use the result of a script with another call, like SADD key EVAL(SHA) .... And also, it's not possible to use global variables within scripts. I've changed the part inside the fields' loop to access the list of ID's outside the script:
if i % 2 == 0 then
ids[#ids + 1] = id
redis.call('SADD', KEYS[1], id)
end
I had to add redis.replicate_commands() to the first line. With this change I can get all ID's from the key I passed when calling the script (see KEYS[1]).
And, finally, to get a list 100 product ID's priced between 40 and 50 where the name contains "ice", I do the following:
> ZUNIONSTORE tmp:price 1 product:price WEIGHTS 1
> ZREMRANGEBYSCORE tmp:price 0 40
> ZREMRANGEBYSCORE tmp:price 50 +INF
> EVALSHA b81c2b... 1 tmp:name ice
> ZINTERSTORE tmp:result tmp:price tmp:name
> ZCOUNT tmp:result -INF +INF
> ZRANGE tmp:result 0 100
I use the ZCOUNT call to know in advance how many result pages I'll have, doing count / 100.
As I said before, this works nicely with Redis 3.2. But when I tried to run the code at AWS, which only supports Redis up to 2.8, I couldn't make it work anymore. I'm not sure how to iterate with HSCAN cursor without using a script or without writing from the script. There is a way to make it work on Redis 2.8?
Some considerations:
I know I can do part of the processing outside Redis (like iterate the cursor or intersect the matches), but it'll affect the application overall performance.
I don't want to deploy a Redis instance by my own to use version 3.2.
The criteria above (price range and name) is just an example to keep things simple here. I have other fields and type of matches, not only those.
I'm not sure if the way I'm storing the data is the best way. I'm willing to listen suggestion about it.
The only problem I found here is storing the values inside a lua scirpt. So instead of storing them inside a lua, take that value outside lua (return that values of string[]). Store them in a set in a different call using sadd (key,members[]). Then proceed with intersection and returning results.
> ZUNIONSTORE tmp:price 1 product:price WEIGHTS 1
> ZREVRANGEBYSCORE tmp:price 0 40
> ZREVRANGEBYSCORE tmp:price 50 +INF
> nameSet[] = EVALSHA b81c2b... 1 ice
> SADD tmp:name nameSet
> ZINTERSTORE tmp:result tmp:price tmp:name
> ZCOUNT tmp:result -INF +INF
> ZRANGE tmp:result 0 100
IMO your design is the most optimal one. One advice would be to use pipeline wherever possible, as it would process everything at one go.
Hope this helps
UPDATE
There is no such thing like array ([ ]) in lua you have to use the lua table to achieve it. In your script you are returning ids right, that itself is an array you can use it as a separate call to achieve the sadd.
String [] nameSet = (String[]) evalsha b81c2b... 1 ice -> This is in java
SADD tmp:name nameSet
And the corresponding lua script is the same as that of your 1st one.
local cursor = 0
local fields = {}
local ids = {}
local key = 'product:name'
local value = '*' .. ARGV[1] .. '*'
repeat
local result = redis.call('HSCAN', key, cursor, 'MATCH', value)
cursor = tonumber(result[1])
fields = result[2]
for i, id in ipairs(fields) do
if i % 2 == 0 then
ids[#ids + 1] = id
end
end
until cursor == 0
return ids
The problem isn't that you're writing to the database, it's that you're doing a write after a HSCAN, which is a non-deterministic command.
In my opinion there's rarely a good reason to use a SCAN command in a Lua script. The main purpose of the command is to allow you to do things in small batches so you don't lock up the server processing a huge key space (or hash key space). Since scripts are atomic, though, using HSCAN doesn't help—you're still locking up the server until the whole thing's done.
Here are the options I can see:
If you can't risk locking up the server with a lengthy command:
Use HSCAN on the client. This is the safest option, but also the slowest.
If you're want to do as much processing in a single atomic Lua command as possible:
Use Redis 3.2 and script effects replication.
Do the scanning in the script, but return the values to the client and initiate the write from there. (That is, Karthikeyan Gopall's answer.)
Instead of HSCAN, do an HKEYS in the script and filter the results using Lua's pattern matching. Since HKEYS is deterministic you won't have a problem with the subsequent write. The downside, of course, is that you have to read in all of the keys first, regardless of whether they match your pattern. (Though HSCAN is also O(N) in the size of the hash.)
I was writing a script to move items in and out of storage in a game. I'd planned to allow for item queues in the event that there was not sufficient free space when I ran the script. I'd also planned to allow for more than one queue to exist at a time (ex: a queue to move items into the inventory, and a second queue to move items into the storage).
I originally thought that I should use coroutines to achieve this. The first queue would run until the destination for items (storage or inventory) was full, then would pause using coroutine.yield and allow the next queue to run. The queues would be restarted when a free space opened up.
threads = {}
local co = coroutine.create(function(list, target)
--list: a list of items to be moved
--target: inventory or storage (where the item is to be moved)
while list.n > 0 do
if target.count < target.max then
move(list:last(), target)
else
coroutine.yield()
end
end
end)
threads:append(co)
-- this code would run when free spaces were detected
for i = 1, #threads do
local status = coroutine.resume(threads[i])
if not status then
threads:remove[i]
end
end
However, I realized that I didn't necessarily need to use coroutines.
inventory_lists = {}
-- lists of items to be moved to the inventory
storage_lists = {}
-- lists of items to be moved to the storage
run_threads = function(list, target)
while list.n > 0 and target.count < target.max do
move(list:last(), target)
end
end
-- this code would run when free spaces were detected
for i = 1, #inventory_lists do
run_threads(inventory_lists[i], inventory)
end
for i = 1, #storage_lists do
run_threads(storage_lists[i], storage)
end
These pieces of code accomplish the same thing, and I don't see any reason to use one over the other. Should I avoid using coroutines in this case, since there doesn't seem to be an advantage?
It seems this is an inappropriate use for coroutines as there simply isn't any need to use them: the tables are all available globally, there's no need to store the state of any variables, and all of the information is immediately available (nothing needs to block).
I suppose it's not incorrect in the sense that it still runs, but it's similar to doing
co = coroutine.wrap(function()
print('Hello') coroutine.yield() print('World')
end)
co() co()
When you could simply print 'Hello\nWorld'.
I've been at this for awhile. I am building a simple lottery website and I am generating random tickets. On my local machine random numbers are generated, however, on the server they are duplicated.
I have tried multiple versions of what I have, but the duplicates is the same.
I need to create a random ticket number per ticket and ensure that it hasn't bee created.
This my like 50th version:
a = Account.find(current_account)
numTics = params[:num_tickets].to_i
t = a.tickets.where(:item_id => item.id).count
total = t + numTics
if total > 5
left = 5 - t
flash[:message] = "The total amount of tickets you can purchase per item is five. You can purchase #{left} more tickets."
redirect_to buy_tickets_path(item.id)
else
i = 1
taken = []
random = Random.new
taken.push(random.rand(100.10000000000000))
code = 0
while i <= numTics do
while(true)
code = random.rand(100.10000000000000)
if !taken.include?(code)
taken.push(code)
if Ticket.exists?(:ticket_number => code) == false
a.tickets.build(
:item_id => item.id,
:ticket_number => code
)
a.save
break
end
code = 0
end
end
i = i + 1
end
session['item_name'] = item.name
price = item.price.to_i * 0.05
total = price * numTics
session['amount_due'] = total.to_i
redirect_to confirmation_path
end
You should be using SecureRandom if possible, not Random. It works the same way but is much more random and doesn't need to be initialized like Random does:
SecureRandom.random_number * 100.1
If you're using Ruby 1.8.7 you can try the ActiveSupport::SecureRandom equivalent.
Also if you're generating lottery tickets, you will want to make sure your generator is cryptographically secure. Generating random numbers alone is probably not sufficient. You will likely want to apply some other function to generate these.
Keep in mind that most actual lotteries do not generate random tickets at the point of purchase, but generate large batches in advance and then issue these to purchasers. This means you are able to preview the tickets and ensure they are sufficiently random.
The problem is not with Ruby's pseudo random number generator but that fact that you are creating generators all the time with Random.new. As explained in this answer, you should not have to call Random.new more than once. Store the result in a global object and you'll be good to go.