我在Talend中创建了一个在表中添加数据的ETL.
该表适用于旧系统,主键不是自动增量.每次我在表中插入一个值时,我必须得到最大id加一.
我正在尝试在表达式构建器中使用var:
然后在表达式构建器中:
Context.Max += 1
Run Code Online (Sandbox Code Playgroud)问题是,每次我得到相同的ID,我需要保存总和.
我的数据如下所示:
CustomerID TripDate
1 1/3/2013
1 1/4/2013
1 1/9/2013
2 2/1/2013
2 2/4/2013
3 1/2/2013
Run Code Online (Sandbox Code Playgroud)
我需要创建一个计数器变量,如下所示:
CustomerID TripDate TripCounter
1 1/3/2013 1
1 1/4/2013 2
1 1/9/2013 3
2 2/1/2013 1
2 2/4/2013 2
3 1/2/2013 1
Run Code Online (Sandbox Code Playgroud)
Tripcounter 将为每个客户.
我从一个非常简单的多线程示例开始.我正在尝试制作线程安全计数器.我想创建两个线程,间歇性地递增计数器以达到1000.代码如下:
public class ThreadsExample implements Runnable {
static int counter = 1; // a global counter
public ThreadsExample() {
}
static synchronized void incrementCounter() {
System.out.println(Thread.currentThread().getName() + ": " + counter);
counter++;
}
@Override
public void run() {
while(counter<1000){
incrementCounter();
}
}
public static void main(String[] args) {
ThreadsExample te = new ThreadsExample();
Thread thread1 = new Thread(te);
Thread thread2 = new Thread(te);
thread1.start();
thread2.start();
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,while循环现在意味着只有第一个线程可以访问计数器,直到达到1000.输出:
Thread-0: 1
.
.
.
Thread-0: 999
Thread-1: 1000
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?如何让线程共享计数器?
我有一个包含多个组件的 React 单页应用程序。对于第 5 个组件(仅在向下滚动时可见),我有一个 counter 。现在我使用 react-countup 库来实现计数器功能。但是,计数器会在页面加载后立即启动。一旦我们向下滚动到组件,是否可以开始计数。动画仅在页面加载后发生一次(这很好),但我希望计数器不会在页面加载后不久开始,而是当用户第一次向下滚动到组件时。我的代码如下所示:
render() {
return (
<div className={style.componentName}>
<h2>Heading</h2>
<div className={style.col}>
<div>My counter</div>
<CountUp className={style.countup} decimals={1} start={0} end={25} suffix=" %" duration={3} />
</div>
</div>)}
Run Code Online (Sandbox Code Playgroud)
更新代码:
import CountUp, { startAnimation } from 'react-countup';
import VisibilitySensor from 'react-visibility-sensor';
class className extends Component {
state = {
scrollStatus: true
};
onVisibilityChange = isVisible => {
if (isVisible) {
if (this.state.scrollStatus) {
startAnimation(this.myCountUp);
this.setState({ scrollStatus: false });
}
}
}
render() {
return (
<div className={style.componentName}>
<h2>Heading</h2> …Run Code Online (Sandbox Code Playgroud) 我一直试图找到一个使用单词递增计数器的函数.我知道可能使用带后缀的数字(即第1,第2,第3等).这是我得到的代码的片段:
function addOrdinalNumberSuffix($num) {
if (!in_array(($num % 100),array(11,12,13))){
switch ($num % 10) {
// Handle 1st, 2nd, 3rd
case 1: return $num.'st';
case 2: return $num.'nd';
case 3: return $num.'rd';
}
}
return $num.'th';
}
Run Code Online (Sandbox Code Playgroud)
但有没有办法用文字复制它(即第一,第二,第三等......)?
我希望创建一个无限的计数器是非常困难的(但并非不可能),但是任何高达20的计数器就足够了.
任何帮助将非常感激.
我正在尝试使用Python Boto 2.3.0更新原子计数计数器,但是找不到该操作的文档.
似乎没有直接接口,所以我尝试使用layer1接口进行"原始"更新,但我甚至无法完成简单的更新.
我尝试了以下变化,但都没有运气
dynoConn.update_item(INFLUENCER_DATA_TABLE,
{'HashKeyElement': "9f08b4f5-d25a-4950-a948-0381c34aed1c"},
{'new': {'Value': {'N':"1"}, 'Action': "ADD"}})
dynoConn.update_item('influencer_data',
{'HashKeyElement': "9f08b4f5-d25a-4950-a948-0381c34aed1c"},
{'new': {'S' :'hello'}})
dynoConn.update_item("influencer_data",
{"HashKeyElement": "9f08b4f5-d25a-4950-a948-0381c34aed1c"},
{"AttributesToPut" : {"new": {"S" :"hello"}}})
Run Code Online (Sandbox Code Playgroud)
它们都会产生相同的错误:
File "/usr/local/lib/python2.6/dist-packages/boto-2.3.0-py2.6.egg/boto/dynamodb/layer1.py", line 164, in _retry_handler
data)
boto.exception.DynamoDBResponseError: DynamoDBResponseError: 400 Bad Request
{u'Message': u'Expected null', u'__type': u'com.amazon.coral.service#SerializationException'}
Run Code Online (Sandbox Code Playgroud)
我做了很多搜索和摆弄,我唯一剩下的就是使用PHP API并深入研究代码以找到它"格式化"JSON主体的位置,但这有点痛苦.请救我脱离这种痛苦!
这可能是一个不寻常的请求,但对于我的脚本,我需要一个按字母而不是数字递增的函数.例如:
这是一个数字示例:
var i = 0;
while(condition){
window.write('We are at '+i);
++i;
}
Run Code Online (Sandbox Code Playgroud)
从本质上讲,我想用字母来计算,比如Microsoft Excel,而不是数字.所以不是打印"我们在0","我们在1","我们在2"等,我需要打印"我们在A","我们在B","我们在C"等
为了模仿Excel(我能想到的唯一例子),在达到索引25(Z)后,我们可以转到'AA','AB','AC'等.
所以它会像这样工作:
var i = 0;
while(condition){
window.write('We are at '+toLetter(i));
++i;
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以写一个函数然后将一个字母转换回一个数字,即toNumber('A')= 0或toNumber('DC')= 107(我认为),那就更好了.
谢谢!
我一直在玩不同的方式(在Python 2.7中)从语料库或字符串列表中提取(单词,频率)元组列表,并比较它们的效率.据我所知,在正常情况下列表未排序的情况下,模块中的Counter方法collections优于我在其他地方提出或找到的任何方法,但它似乎没有太大的好处.预先排序的列表,我已经提出了在这种特殊情况下轻松击败它的方法.那么,简而言之,是否有任何内置的方法来告知Counter列表已经排序以进一步加快它的速度?
(下一部分是未分类的列表,其中Counter工作魔法;你可能想要在处理排序列表时跳到它失去魅力的那一端.)
天真的方法是使用sorted([(word, corpus.count(word)) for word in set(corpus)]),但一个可靠的,只要你的语料库是几千个条目你进入运行时的问题-这并不奇怪,因为你通过的n个字的完整列表运行男也曾多次,其中m为唯一单词的数量.
因此,我试图做之前,而不是我发现的Counter是确保所有的搜索都是严格的地方,首先分拣输入表(我也有删除的数字和标点符号和所有条目转换为小写,以避免像"富"重复, 'Foo'和'foo:').
#Natural Language Toolkit, for access to corpus; any other source for a long text will do, though.
import nltk
# nltk corpora come as a class of their own, as I udnerstand it presenting to the
# outside as a unique list but underlyingly represented as several lists, with no more
# than one ever …Run Code Online (Sandbox Code Playgroud) Cassandra是否支持Counter列族的TTL?
具体来说,我们使用Hector作为Cassandra的客户端,我没有找到任何接收TTL作为参数的API.至少HFactory.createCounterColumn没有TTL参数.
我想知道一个单词中有多少个字符重复.重复必须是连续的.
例如,输入"loooooveee"的方法应该返回6('o'的4次,'e'的2次).
我正在尝试实现字符串级别的功能,我可以这样做但是,有一种简单的方法可以做到这一点吗?正则表达式,还是其他一些东西?
到目前为止我试过这个:
__PRE__
它以"loooooveee"返回8.